diff --git a/packages/smooth_app/lib/pages/product/edit_new_packagings.dart b/packages/smooth_app/lib/pages/product/edit_new_packagings.dart index 9d9e123a96c0..84bf8e0be4bb 100644 --- a/packages/smooth_app/lib/pages/product/edit_new_packagings.dart +++ b/packages/smooth_app/lib/pages/product/edit_new_packagings.dart @@ -320,7 +320,11 @@ class _EditNewPackagingsState extends State { if (pleaseSave == false) { return true; } + if (!mounted) { + return false; + } } + await BackgroundTaskDetails.addTask( changedProduct, widget: this, diff --git a/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart b/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart index 8fead4174f80..9d9e328c7a83 100644 --- a/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart +++ b/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart @@ -11,6 +11,7 @@ import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; import 'package:smooth_app/generic_lib/widgets/smooth_card.dart'; import 'package:smooth_app/helpers/text_input_formatters_helper.dart'; import 'package:smooth_app/pages/product/common/product_refresher.dart'; +import 'package:smooth_app/pages/product/may_exit_page_helper.dart'; import 'package:smooth_app/pages/product/nutrition_add_nutrient_button.dart'; import 'package:smooth_app/pages/product/nutrition_container.dart'; import 'package:smooth_app/pages/product/ordered_nutrients_cache.dart'; @@ -502,36 +503,25 @@ class _NutritionPageLoadedState extends State { } final AppLocalizations appLocalizations = AppLocalizations.of(context); if (!saving) { - final bool? pleaseSave = await showDialog( - context: context, - builder: (final BuildContext context) => SmoothAlertDialog( - close: true, - body: Text(appLocalizations.edit_product_form_item_exit_confirmation), - title: appLocalizations.nutrition_page_title, - negativeAction: SmoothActionButton( - text: appLocalizations.ignore, - onPressed: () => Navigator.pop(context, false), - ), - positiveAction: SmoothActionButton( - text: appLocalizations.save, - onPressed: () => Navigator.pop(context, true), - ), - ), - ); + final bool? pleaseSave = + await MayExitPageHelper().openSaveBeforeLeavingDialog(context); if (pleaseSave == null) { return false; } if (pleaseSave == false) { return true; } - } - if (!mounted) { - return false; + if (!mounted) { + return false; + } } final Product? changedProduct = _getChangedProduct(Product(barcode: widget.product.barcode)); if (changedProduct == null) { + if (!mounted) { + return false; + } ScaffoldMessenger.of(context).showSnackBar( SnackBar( // here I cheat and I reuse the only invalid case. diff --git a/packages/smooth_app/lib/pages/product/simple_input_page.dart b/packages/smooth_app/lib/pages/product/simple_input_page.dart index 09973acec460..ae9257615ac2 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_page.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_page.dart @@ -173,7 +173,11 @@ class _SimpleInputPageState extends State { if (pleaseSave == false) { return true; } + if (!mounted) { + return false; + } } + await BackgroundTaskDetails.addTask( changedProduct, widget: this, diff --git a/packages/smooth_app/lib/tmp_crop_image/new_crop_page.dart b/packages/smooth_app/lib/tmp_crop_image/new_crop_page.dart index e9b10b0f5b6b..4f2104983f97 100644 --- a/packages/smooth_app/lib/tmp_crop_image/new_crop_page.dart +++ b/packages/smooth_app/lib/tmp_crop_image/new_crop_page.dart @@ -289,6 +289,9 @@ class _CropPageState extends State { if (pleaseSave == false) { return true; } + if (!mounted) { + return false; + } } return _saveFileAndExit();