Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #2169 - new simple input page for "Labels" #2202

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class SmoothAlertDialog extends StatelessWidget {
this.positiveAction,
this.neutralAction,
this.negativeAction,
}) : close = false,
maxHeight = null,
this.close = false,
}) : maxHeight = null,
_simpleMode = true;

/// Advanced alert dialog with fancy effects.
Expand Down Expand Up @@ -153,7 +153,7 @@ class SmoothAlertDialog extends StatelessWidget {
Icons.close,
size: 29.0,
),
onTap: () => Navigator.of(context, rootNavigator: true).pop('dialog'),
onTap: () => Navigator.of(context, rootNavigator: true).pop(),
),
);
} else {
Expand Down
17 changes: 17 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"skip": "Skip",
"cancel": "Cancel",
"@cancel": {},
"ignore": "Ignore",
"@ignore": {
"description": "'Ignore' button. Typical use case in combination with 'OK' and 'Cancel' buttons."
},
"close": "Close",
"@close": {},
"no": "No",
Expand Down Expand Up @@ -879,6 +883,19 @@
"@edit_product_form_item_labels_subtitle": {
"description": "Product edition - Labels - SubTitle"
},
"edit_product_form_item_labels_hint": "label",
"@edit_product_form_item_labels_hint": {
"description": "Product edition - Labels - input textfield hint"
},
"edit_product_form_item_stores_title": "Stores",
"@edit_product_form_item_stores_title": {
"description": "Product edition - Stores - Title"
},
"edit_product_form_item_stores_hint": "label",
"@edit_product_form_item_stores_hint": {
"description": "Product edition - Stores - input textfield hint"
},
"edit_product_form_item_exit_confirmation": "Do you want to save your changes before leaving this page?",
"edit_product_form_item_ingredients_title": "Ingredients & Origins",
"@edit_product_form_item_ingredients_title": {
"description": "Product edition - Ingredients - Title"
Expand Down
17 changes: 17 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"skip": "Ignorer",
"cancel": "Annuler",
"@cancel": {},
"ignore": "Ignorer",
"@ignore": {
"description": "'Ignore' button. Typical use case in combination with 'OK' and 'Cancel' buttons."
},
"close": "Fermer",
"@close": {},
"no": "Non",
Expand Down Expand Up @@ -871,6 +875,19 @@
"@edit_product_form_item_labels_subtitle": {
"description": "Product edition - Labels - SubTitle"
},
"edit_product_form_item_labels_hint": "label",
"@edit_product_form_item_labels_hint": {
"description": "Product edition - Labels - input textfield hint"
},
"edit_product_form_item_stores_title": "Magasins",
"@edit_product_form_item_stores_title": {
"description": "Product edition - Stores - Title"
},
"edit_product_form_item_stores_hint": "magasin",
"@edit_product_form_item_stores_hint": {
"description": "Product edition - Stores - input textfield hint"
},
"edit_product_form_item_exit_confirmation": "Voulez-vous sauver vos modifications avant de quitter cette page ?",
"edit_product_form_item_ingredients_title": "Ingrédients & Origines",
"@edit_product_form_item_ingredients_title": {
"description": "Product edition - Ingredients - Title"
Expand Down
44 changes: 22 additions & 22 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ class _EditProductPageState extends State<EditProductPage> {
}
},
),
_ListTitleItem(
title: appLocalizations.edit_product_form_item_labels_title,
subtitle: appLocalizations.edit_product_form_item_labels_subtitle,
_getSimpleListTileItem(
SimpleInputPageLabelHelper(_product, appLocalizations),
),
_ListTitleItem(
title: appLocalizations.edit_product_form_item_ingredients_title,
Expand All @@ -126,25 +125,8 @@ class _EditProductPageState extends State<EditProductPage> {
_ListTitleItem(
title: appLocalizations.edit_product_form_item_packaging_title,
),
_ListTitleItem(
title: 'Stores', // TODO(monsieurtanuki): translate
onTap: () async {
final Product? refreshed = await Navigator.push<Product>(
context,
MaterialPageRoute<Product>(
builder: (BuildContext context) => SimpleInputPage(
SimpleInputPageStoreHelper(
_product,
appLocalizations,
),
),
),
);
if (refreshed != null) {
_product = refreshed;
}
return;
},
_getSimpleListTileItem(
SimpleInputPageStoreHelper(_product, appLocalizations),
),
_ListTitleItem(
title:
Expand Down Expand Up @@ -179,6 +161,24 @@ class _EditProductPageState extends State<EditProductPage> {
),
);
}

Widget _getSimpleListTileItem(final AbstractSimpleInputPageHelper helper) =>
_ListTitleItem(
title: helper.getTitle(),
subtitle: helper.getSubtitle(),
onTap: () async {
final Product? refreshed = await Navigator.push<Product>(
context,
MaterialPageRoute<Product>(
builder: (BuildContext context) => SimpleInputPage(helper),
),
);
if (refreshed != null) {
_product = refreshed;
}
setState(() {});
},
);
}

class _ListTitleItem extends StatelessWidget {
Expand Down
27 changes: 12 additions & 15 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';

/// Simple input page: we have a list of labels, we add, we remove, we save.
/// Simple input page: we have a list of terms, we add, we remove, we save.
class SimpleInputPage extends StatefulWidget {
const SimpleInputPage(this.helper) : super();

Expand Down Expand Up @@ -41,21 +41,18 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
final bool? pleaseSave = await showDialog<bool>(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
close: true,
body:
const Text('You are about to leave this page without saving.'),
Text(appLocalizations.edit_product_form_item_exit_confirmation),
title: widget.helper.getTitle(),
negativeAction: SmoothActionButton(
text: 'Ignore',
text: appLocalizations.ignore,
onPressed: () => Navigator.pop(context, false),
),
positiveAction: SmoothActionButton(
text: 'Save',
text: appLocalizations.save,
onPressed: () => Navigator.pop(context, true),
),
neutralAction: SmoothActionButton(
text: 'Cancel',
onPressed: () => Navigator.pop(context, null),
),
),
);
if (pleaseSave == null) {
Expand Down Expand Up @@ -96,13 +93,13 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
widget.helper.getTitle(),
style: themeData.textTheme.headline1,
),
const SizedBox(height: LARGE_SPACE),
Text(widget.helper.getAddTitle()),
if (widget.helper.getSubtitle() != null)
Text(widget.helper.getSubtitle()!),
Row(
children: <Widget>[
ElevatedButton(
onPressed: () {
if (widget.helper.addLabel(_controller.text)) {
if (widget.helper.addTerm(_controller.text)) {
setState(() => _controller.text = '');
}
},
Expand Down Expand Up @@ -137,14 +134,14 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
spacing: LARGE_SPACE,
runSpacing: VERY_SMALL_SPACE,
children: List<Widget>.generate(
widget.helper.getLabels().length,
widget.helper.terms.length,
(final int index) {
final String label = widget.helper.getLabels()[index];
final String term = widget.helper.terms[index];
return ElevatedButton.icon(
icon: const Icon(Icons.clear),
label: Text(label),
label: Text(term),
onPressed: () async {
if (widget.helper.removeLabel(label)) {
if (widget.helper.removeTerm(term)) {
setState(() {});
}
},
Expand Down
Loading