Skip to content

Commit

Permalink
fix: 3516 - standardized the "do you want to save" dialog? (#3520)
Browse files Browse the repository at this point in the history
Impacted files:
* `edit_new_packagings.dart`: minor refactoring
* `new_crop_page.dart`: minor refactoring
* `nutrition_page_loaded.dart`: now using `MayExitPageHelper` as dialog
* `simple_input_page.dart`: minor refactoring

Co-authored-by: Aman Raj <57723319+AshAman999@users.noreply.github.com>
  • Loading branch information
monsieurtanuki and AshAman999 authored Jan 5, 2023
1 parent bdca5d4 commit d61ca4b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ class _EditNewPackagingsState extends State<EditNewPackagings> {
if (pleaseSave == false) {
return true;
}
if (!mounted) {
return false;
}
}

await BackgroundTaskDetails.addTask(
changedProduct,
widget: this,
Expand Down
28 changes: 9 additions & 19 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -502,36 +503,25 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded> {
}
final AppLocalizations appLocalizations = AppLocalizations.of(context);
if (!saving) {
final bool? pleaseSave = await showDialog<bool>(
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.
Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
if (pleaseSave == false) {
return true;
}
if (!mounted) {
return false;
}
}

await BackgroundTaskDetails.addTask(
changedProduct,
widget: this,
Expand Down
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/tmp_crop_image/new_crop_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ class _CropPageState extends State<CropPage> {
if (pleaseSave == false) {
return true;
}
if (!mounted) {
return false;
}
}

return _saveFileAndExit();
Expand Down

0 comments on commit d61ca4b

Please sign in to comment.