From 992de284507fabde7e0bf3884da8d1d7935cc386 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Fri, 10 Feb 2023 17:15:29 +0100 Subject: [PATCH] Polish the last exercise submission step Show a spinner while the requests are being processed (still no error handling here though) and show a pop up on success that allows the user to go to the exercise's detail page Closes #341 --- lib/l10n/app_en.arb | 5 +++ lib/providers/add_exercise.dart | 6 +-- lib/screens/add_exercise_screen.dart | 59 ++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 14e6759e..7a68d7c1 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -93,6 +93,10 @@ "@labelDashboard": { "description": "Title for screen dashboard" }, + "success": "Success", + "@success": { + "description": "Message when an action completed successfully, usually used as a heading" + }, "successfullyDeleted": "Deleted", "@successfullyDeleted": { "description": "Message when an item was successfully deleted" @@ -629,6 +633,7 @@ } } }, + "cacheWarning": "Due to caching it might take some time till the changes are visible throughout the application.", "abs": "Abs", "arms": "Arms", "back": "Back", diff --git a/lib/providers/add_exercise.dart b/lib/providers/add_exercise.dart index f434f7d5..67899797 100644 --- a/lib/providers/add_exercise.dart +++ b/lib/providers/add_exercise.dart @@ -204,12 +204,12 @@ class AddExerciseProvider with ChangeNotifier { await addExerciseTranslation(exerciseTranslationLang); } - // Clear everything - //clear(); - // Create the images await addImages(base); + // Clear everything + clear(); + // Return exercise ID return base.id!; } diff --git a/lib/screens/add_exercise_screen.dart b/lib/screens/add_exercise_screen.dart index 75d9b4c0..4d65f0b6 100644 --- a/lib/screens/add_exercise_screen.dart +++ b/lib/screens/add_exercise_screen.dart @@ -41,6 +41,8 @@ class AddExerciseStepper extends StatefulWidget { class _AddExerciseStepperState extends State { int _currentStep = 0; int lastStepIndex = AddExerciseStepper.STEPS_IN_FORM - 1; + bool _isLoading = false; + final List> _keys = [ GlobalKey(), GlobalKey(), @@ -57,17 +59,58 @@ class _AddExerciseStepperState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ OutlinedButton( - onPressed: details.onStepCancel, - child: Text(AppLocalizations.of(context).previous)), + onPressed: details.onStepCancel, + child: Text(AppLocalizations.of(context).previous), + ), if (_currentStep == lastStepIndex) ElevatedButton( - onPressed: () async { - final id = await context.read().addExercise(); - final base = await context.read().fetchAndSetExerciseBase(id); + onPressed: _isLoading + ? null + : () async { + setState(() { + _isLoading = true; + }); + final addExerciseProvider = context.read(); + final exerciseProvider = context.read(); - Navigator.pushNamed(context, ExerciseDetailScreen.routeName, arguments: base); - }, - child: Text(AppLocalizations.of(context).save), + final baseId = await addExerciseProvider.addExercise(); + final base = await exerciseProvider.fetchAndSetExerciseBase(baseId); + final name = + base.getExercise(Localizations.localeOf(context).languageCode).name; + + setState(() { + _isLoading = false; + }); + + if (!context.mounted) return; + return showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text(AppLocalizations.of(context).success), + content: Text(AppLocalizations.of(context).cacheWarning), + actions: [ + TextButton( + child: Text(name), + onPressed: () { + Navigator.of(context).pop(); + Navigator.pushReplacementNamed( + context, ExerciseDetailScreen.routeName, + arguments: base); + }, + ), + ], + ); + }, + ); + }, + child: _isLoading + ? const SizedBox( + height: 20, + width: 20, + child: CircularProgressIndicator(), + ) + : Text(AppLocalizations.of(context).save), ) else ElevatedButton(