diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index cfba158b83c0..7fcae2dc3753 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -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." diff --git a/packages/smooth_app/lib/l10n/app_fr.arb b/packages/smooth_app/lib/l10n/app_fr.arb index 1418af21d878..b4482ed48d1d 100644 --- a/packages/smooth_app/lib/l10n/app_fr.arb +++ b/packages/smooth_app/lib/l10n/app_fr.arb @@ -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." diff --git a/packages/smooth_app/lib/pages/product/add_new_product_page.dart b/packages/smooth_app/lib/pages/product/add_new_product_page.dart index f7d2d5eeeb71..f4d5bd783e33 100644 --- a/packages/smooth_app/lib/pages/product/add_new_product_page.dart +++ b/packages/smooth_app/lib/pages/product/add_new_product_page.dart @@ -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'; @@ -107,27 +108,51 @@ class _AddNewProductPageState extends State { _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( + 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: [ - _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: [ + _buildCard(_getImageRows(context)), + _buildCard(_getNutriscoreRows(context)), + _buildCard(_getEcoscoreRows(context)), + _buildCard(_getMiscRows(context)), + const SizedBox(height: MINIMUM_TOUCH_SIZE), + ], + ), ), ), ),