Skip to content

Commit

Permalink
Fast track: ensure the navigation works as intended (#4891)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Dec 11, 2023
1 parent 5ffdca3 commit 36fb948
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
8 changes: 8 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"@next_label": {
"description": "A label on a button that says 'Next', pressing the button takes the user to the next screen."
},
"previous_label": "Previous",
"@previous_label": {
"description": "A label on a button that says 'Previous', pressing the button takes the user to the previous screen."
},
"go_back_to_top": "Go back to top",
"save": "Save",
"save_confirmation": "Are you sure you want to save?",
Expand Down Expand Up @@ -541,6 +545,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_title": "Leave this page?",
"@new_product_leave_title": {
"description": "Alert dialog title when a user landed on the 'add new product' page, didn't input anything and tried to leave the page."
},
"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."
Expand Down
44 changes: 29 additions & 15 deletions packages/smooth_app/lib/pages/product/add_new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,16 @@ class _AddNewProductPageState extends State<AddNewProductPage>
final bool? leaveThePage = await showDialog<bool>(
context: context,
builder: (final BuildContext context) => SmoothAlertDialog(
title: appLocalizations.new_product,
title: appLocalizations.new_product_leave_title,
actionsAxis: Axis.vertical,
body: Text(appLocalizations.new_product_leave_message),
body: Padding(
padding: const EdgeInsetsDirectional.only(
bottom: MEDIUM_SPACE,
start: MEDIUM_SPACE,
end: MEDIUM_SPACE,
),
child: Text(appLocalizations.new_product_leave_message),
),
positiveAction: SmoothActionButton(
text: appLocalizations.yes,
onPressed: () => Navigator.of(context).pop(true),
Expand Down Expand Up @@ -319,10 +326,7 @@ class _AddNewProductPageState extends State<AddNewProductPage>
width: 20.0,
height: 20.0,
child: IconButton(
onPressed: () => _onWillPop().then(
(bool leaveThePage) =>
leaveThePage ? Navigator.of(context).pop() : null,
),
onPressed: () => Navigator.of(context).maybePop(),
alignment: Alignment.center,
padding: EdgeInsets.zero,
icon: const Icon(Icons.arrow_back),
Expand All @@ -343,13 +347,19 @@ class _AddNewProductPageState extends State<AddNewProductPage>
),
),
onPressed: () {
_onWillPop().then(
(bool leaveThePage) =>
leaveThePage ? Navigator.of(context).pop() : null,
);
if ((_pageController.page ?? 0.0) < 1.0) {
Navigator.of(context).maybePop();
} else {
_pageController.previousPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
);
}
},
child: Text(
AppLocalizations.of(context).cancel,
(_pageController.hasClients ? _pageController.page! : 0.0) >= 1.0
? AppLocalizations.of(context).previous_label
: AppLocalizations.of(context).cancel,
style: const TextStyle(
color: Colors.black,
fontSize: 20.0,
Expand All @@ -367,10 +377,14 @@ class _AddNewProductPageState extends State<AddNewProductPage>
),
),
onPressed: () {
_pageController.nextPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
);
if (_isLastPage) {
Navigator.of(context).pop();
} else {
_pageController.nextPage(
duration: SmoothAnimationsDuration.short,
curve: Curves.easeOut,
);
}
},
child: Text(
_isLastPage
Expand Down

0 comments on commit 36fb948

Please sign in to comment.