From 96ac3b2ec687f0b5ac14fae6034678b360d07c2f Mon Sep 17 00:00:00 2001 From: Thilina Herath Date: Wed, 6 Oct 2021 18:23:01 +0800 Subject: [PATCH 1/2] Bad internet duplicate exercise entries #54 --- lib/widgets/workouts/gym_mode.dart | 76 ++++++++++++++++++------------ 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/lib/widgets/workouts/gym_mode.dart b/lib/widgets/workouts/gym_mode.dart index d424b287..c217d597 100644 --- a/lib/widgets/workouts/gym_mode.dart +++ b/lib/widgets/workouts/gym_mode.dart @@ -45,9 +45,11 @@ import 'package:wger/widgets/workouts/forms.dart'; class GymMode extends StatefulWidget { final Day _workoutDay; late TimeOfDay _start; + GymMode(this._workoutDay) { _start = TimeOfDay.now(); } + @override _GymModeState createState() => _GymModeState(); } @@ -60,6 +62,7 @@ class _GymModeState extends State { final PageController _controller = PageController( initialPage: 0, ); + @override void dispose() { _controller.dispose(); @@ -256,6 +259,7 @@ class _LogPageState extends State { final _repsController = TextEditingController(); final _weightController = TextEditingController(); var _detailed = false; + int _state = 0; late FocusNode focusNode; @@ -456,37 +460,51 @@ class _LogPageState extends State { }, ), ElevatedButton( - child: Text(AppLocalizations.of(context).save), - onPressed: () async { - // Validate and save the current values to the weightEntry - final isValid = _form.currentState!.validate(); - if (!isValid) { - return; - } - _form.currentState!.save(); - - // Save the entry on the server - try { - await Provider.of(context, listen: false).addLog(widget._log); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: Duration(seconds: 2), // default is 4 - content: Text( - AppLocalizations.of(context).successfullySaved, - textAlign: TextAlign.center, + child: (_state == 0) + ? Text(AppLocalizations.of(context).save) + : Container( + height: 20, + width: 20, + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Colors.white), ), ), - ); - widget._controller.nextPage( - duration: DEFAULT_ANIMATION_DURATION, - curve: DEFAULT_ANIMATION_CURVE, - ); - } on WgerHttpException catch (error) { - showHttpExceptionErrorDialog(error, context); - } catch (error) { - showErrorDialog(error, context); - } - }, + onPressed: _state == 1 + ? null + : () async { + // Validate and save the current values to the weightEntry + final isValid = _form.currentState!.validate(); + if (!isValid) { + return; + } + _state = 1; + _form.currentState!.save(); + + // Save the entry on the server + try { + await Provider.of(context, listen: false).addLog(widget._log); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: Duration(seconds: 2), // default is 4 + content: Text( + AppLocalizations.of(context).successfullySaved, + textAlign: TextAlign.center, + ), + ), + ); + widget._controller.nextPage( + duration: DEFAULT_ANIMATION_DURATION, + curve: DEFAULT_ANIMATION_CURVE, + ); + _state = 0; + } on WgerHttpException catch (error) { + showHttpExceptionErrorDialog(error, context); + _state = 0; + } catch (error) { + showErrorDialog(error, context); + _state = 0; + } + }, ), ], ), From 27cbbed38fcff517e49863afafd11e21212a02eb Mon Sep 17 00:00:00 2001 From: Thilina Herath Date: Wed, 6 Oct 2021 18:37:49 +0800 Subject: [PATCH 2/2] Update gym_mode.dart --- lib/widgets/workouts/gym_mode.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/widgets/workouts/gym_mode.dart b/lib/widgets/workouts/gym_mode.dart index c217d597..9ecc9aca 100644 --- a/lib/widgets/workouts/gym_mode.dart +++ b/lib/widgets/workouts/gym_mode.dart @@ -259,7 +259,7 @@ class _LogPageState extends State { final _repsController = TextEditingController(); final _weightController = TextEditingController(); var _detailed = false; - int _state = 0; + bool _isSaving = false; late FocusNode focusNode; @@ -460,7 +460,7 @@ class _LogPageState extends State { }, ), ElevatedButton( - child: (_state == 0) + child: (!_isSaving) ? Text(AppLocalizations.of(context).save) : Container( height: 20, @@ -469,7 +469,7 @@ class _LogPageState extends State { valueColor: AlwaysStoppedAnimation(Colors.white), ), ), - onPressed: _state == 1 + onPressed: _isSaving ? null : () async { // Validate and save the current values to the weightEntry @@ -477,7 +477,7 @@ class _LogPageState extends State { if (!isValid) { return; } - _state = 1; + _isSaving = true; _form.currentState!.save(); // Save the entry on the server @@ -496,13 +496,13 @@ class _LogPageState extends State { duration: DEFAULT_ANIMATION_DURATION, curve: DEFAULT_ANIMATION_CURVE, ); - _state = 0; + _isSaving = false; } on WgerHttpException catch (error) { showHttpExceptionErrorDialog(error, context); - _state = 0; + _isSaving = false; } catch (error) { showErrorDialog(error, context); - _state = 0; + _isSaving = false; } }, ),