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

fix: 4155 - check when the user leaves the product addition page if something was input #4156

Merged
merged 1 commit into from
Jun 15, 2023
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
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