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
This commit is contained in:
Roland Geider
2023-02-10 17:15:29 +01:00
parent 6477e39dce
commit 992de28450
3 changed files with 59 additions and 11 deletions

View File

@@ -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",

View File

@@ -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!;
}

View File

@@ -41,6 +41,8 @@ class AddExerciseStepper extends StatefulWidget {
class _AddExerciseStepperState extends State<AddExerciseStepper> {
int _currentStep = 0;
int lastStepIndex = AddExerciseStepper.STEPS_IN_FORM - 1;
bool _isLoading = false;
final List<GlobalKey<FormState>> _keys = [
GlobalKey<FormState>(),
GlobalKey<FormState>(),
@@ -57,17 +59,58 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> {
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<AddExerciseProvider>().addExercise();
final base = await context.read<ExercisesProvider>().fetchAndSetExerciseBase(id);
onPressed: _isLoading
? null
: () async {
setState(() {
_isLoading = true;
});
final addExerciseProvider = context.read<AddExerciseProvider>();
final exerciseProvider = context.read<ExercisesProvider>();
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(