diff --git a/lib/widgets/core/progress_indicator.dart b/lib/widgets/core/progress_indicator.dart index d81261d0..826c8b05 100644 --- a/lib/widgets/core/progress_indicator.dart +++ b/lib/widgets/core/progress_indicator.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; class BoxedProgressIndicator extends StatelessWidget { - const BoxedProgressIndicator({ - super.key, - }); + const BoxedProgressIndicator({super.key}); @override Widget build(BuildContext context) { @@ -13,3 +11,18 @@ class BoxedProgressIndicator extends StatelessWidget { ); } } + +class FormProgressIndicator extends StatelessWidget { + const FormProgressIndicator({super.key}); + + @override + Widget build(BuildContext context) { + return const SizedBox( + height: 20, + width: 20, + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Colors.white), + ), + ); + } +} diff --git a/lib/widgets/routines/forms/routine.dart b/lib/widgets/routines/forms/routine.dart index 8ec84966..4af8c684 100644 --- a/lib/widgets/routines/forms/routine.dart +++ b/lib/widgets/routines/forms/routine.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/models/workouts/routine.dart'; import 'package:wger/providers/routines.dart'; +import 'package:wger/widgets/core/progress_indicator.dart'; class RoutineForm extends StatefulWidget { final Routine _routine; @@ -18,6 +19,7 @@ class RoutineForm extends StatefulWidget { class _RoutineFormState extends State { final _form = GlobalKey(); + bool isSaving = false; late bool fitInWeek; late DateTime startDate; late DateTime endDate; @@ -196,26 +198,36 @@ class _RoutineFormState extends State { const SizedBox(height: 5), ElevatedButton( key: const Key(SUBMIT_BUTTON_KEY_NAME), - child: Text(AppLocalizations.of(context).save), - onPressed: () async { - // Validate and save - final isValid = _form.currentState!.validate(); - if (!isValid) { - return; - } - _form.currentState!.save(); + onPressed: isSaving + ? null + : () async { + // Validate and save + final isValid = _form.currentState!.validate(); + if (!isValid) { + return; + } + _form.currentState!.save(); + setState(() { + isSaving = true; + }); - // Save to DB - if (widget._routine.id != null) { - await Provider.of(context, listen: false) - .editRoutine(widget._routine); - } else { - final Routine newPlan = await Provider.of( - context, - listen: false, - ).addRoutine(widget._routine); - } - }, + // Save to DB + if (widget._routine.id != null) { + await Provider.of(context, listen: false) + .editRoutine(widget._routine); + } else { + final Routine newPlan = await Provider.of( + context, + listen: false, + ).addRoutine(widget._routine); + } + + setState(() { + isSaving = false; + }); + }, + child: + isSaving ? const FormProgressIndicator() : Text(AppLocalizations.of(context).save), ), ], ),