Skip to content

Commit

Permalink
fix: 4155 - check when the user leaves the product addition page if s…
Browse files Browse the repository at this point in the history
…omething was input (#4156)

Impacted files:
* `add_new_product_page.dart`: check when the user leaves the page if something was input
* `app_en.arb`: added 1 label
* `app_fr.arb`: added 1 label
  • Loading branch information
monsieurtanuki committed Jun 15, 2023
1 parent 85fcde1 commit 03d2dcb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@
"@new_product_dialog_title": {
"description": "Please keep it short, like 50 characters. Title of the dialog when the user searched for an unknown barcode."
},
"new_product_leave_message": "It looks like you didn't input anything. Do you really want to leave this page?",
"@new_product_leave_message": {
"description": "Alert dialog message when a user landed on the 'add new product' page, didn't input anything and tried to leave the page."
},
"new_product_dialog_description": "Please take photos of the packaging to add this product to our common database",
"@new_product_dialog_description": {
"description": "Please keep it short, like less than 100 characters. Explanatory text of the dialog when the user searched for an unknown barcode."
Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@
"@new_product_dialog_title": {
"description": "Please keep it short, like 50 characters. Title of the dialog when the user searched for an unknown barcode."
},
"new_product_leave_message": "Apparemment vous n'avez rien saisi. Voulez-vous vraiment quitter cette page ?",
"@new_product_leave_message": {
"description": "Alert dialog message when a user landed on the 'add new product' page, didn't input anything and tried to leave the page."
},
"new_product_dialog_description": "Veuillez prendre des photos de l'emballage pour ajouter ce produit à notre base de données commune",
"@new_product_dialog_description": {
"description": "Please keep it short, like less than 100 characters. Explanatory text of the dialog when the user searched for an unknown barcode."
Expand Down
65 changes: 45 additions & 20 deletions packages/smooth_app/lib/pages/product/add_new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_large_button_with_icon.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/svg_icon_chip.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
Expand Down Expand Up @@ -107,27 +108,51 @@ class _AddNewProductPageState extends State<AddNewProductPage> {

_addToHistory();

return SmoothScaffold(
appBar: AppBar(
title: ListTile(
title: Text(_product.productName ?? appLocalizations.new_product),
subtitle: Text(barcode),
),
),
body: Padding(
padding: const EdgeInsetsDirectional.symmetric(
vertical: VERY_LARGE_SPACE,
return WillPopScope(
onWillPop: () async {
if (_isPopulated) {
return true;
}
final bool? leaveThePage = await showDialog<bool>(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
title: appLocalizations.new_product,
actionsAxis: Axis.vertical,
body: Text(appLocalizations.new_product_leave_message),
positiveAction: SmoothActionButton(
text: appLocalizations.yes,
onPressed: () => Navigator.of(context).pop(true),
),
negativeAction: SmoothActionButton(
text: appLocalizations.cancel,
onPressed: () => Navigator.of(context).pop(false),
),
),
);
return leaveThePage ?? false;
},
child: SmoothScaffold(
appBar: AppBar(
title: ListTile(
title: Text(_product.productName ?? appLocalizations.new_product),
subtitle: Text(barcode),
),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildCard(_getImageRows(context)),
_buildCard(_getNutriscoreRows(context)),
_buildCard(_getEcoscoreRows(context)),
_buildCard(_getMiscRows(context)),
const SizedBox(height: MINIMUM_TOUCH_SIZE),
],
body: Padding(
padding: const EdgeInsetsDirectional.symmetric(
vertical: VERY_LARGE_SPACE,
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildCard(_getImageRows(context)),
_buildCard(_getNutriscoreRows(context)),
_buildCard(_getEcoscoreRows(context)),
_buildCard(_getMiscRows(context)),
const SizedBox(height: MINIMUM_TOUCH_SIZE),
],
),
),
),
),
Expand Down

0 comments on commit 03d2dcb

Please sign in to comment.