From 7e0a374f5a691642c59e9173402b06080c55cfdf Mon Sep 17 00:00:00 2001 From: Felix Holz Date: Wed, 14 Feb 2024 10:52:04 +0100 Subject: [PATCH] fix goal error handling --- lib/screens/edit_goal_data_screen.dart | 57 +++++++++++++------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/screens/edit_goal_data_screen.dart b/lib/screens/edit_goal_data_screen.dart index 97c43e6..f719cd1 100644 --- a/lib/screens/edit_goal_data_screen.dart +++ b/lib/screens/edit_goal_data_screen.dart @@ -162,8 +162,10 @@ class _EditGoalDataScreenState extends State { child: FredericButton( widget.isNewGoal ? 'Create' : 'Save', onPressed: () { - saveData(); - Navigator.of(context).pop(); + final success = saveData(); + if (success) { + Navigator.of(context).pop(); + } })), ], ), @@ -193,40 +195,35 @@ class _EditGoalDataScreenState extends State { return FormError.Success; } - void saveData() { - Future _showErrorMessage(String text) async { - await showDialog( - context: context, - builder: (ctx) { - return Container(); - }, - ); - await showDialog( - context: context, - builder: (ctx) { - return FredericActionDialog( - title: text, - infoOnly: true, - onConfirm: () => Navigator.of(ctx).pop()); - }, - ); - } + Future _showErrorMessage(String text) async { + await showDialog( + context: context, + builder: (ctx) { + return FredericActionDialog( + title: text, + infoOnly: true, + onConfirm: () {}, + ); + }, + ); + } + bool saveData() { if (widget.isNewGoal) { final formStatus = _checkFormInputs(); switch (formStatus) { case FormError.CurrentStateEqualsEndStart: _showErrorMessage('The current state must not match the end state!'); - return; + return false; case FormError.StartStateEqualsEndState: _showErrorMessage('The start state must not match the end state!'); - return; + return false; case FormError.StartDateEqualsEndDate: _showErrorMessage('The start date must not match the end date!'); - break; + return false; case FormError.EndDateSmallerThenStartDate: _showErrorMessage('The end date must not be before the start date!'); - break; + return false; case FormError.Success: widget.goal.updateData( activityID: dummyActivity == null ? '' : dummyActivity!.id, @@ -247,10 +244,10 @@ class _EditGoalDataScreenState extends State { .add(FredericGoalCreateEvent(widget.goal)); FredericBackend.instance.userManager.state.goalsCount += 1; - return; + return true; default: _showErrorMessage('Some error happened'); - return; + return false; } } else { widget.goal.updateData( @@ -266,6 +263,8 @@ class _EditGoalDataScreenState extends State { FredericBackend.instance.goalManager .add(FredericGoalUpdateEvent(widget.goal)); } + + return true; } void addNewActivityTracker(BuildContext context) { @@ -338,8 +337,10 @@ class _EditGoalDataScreenState extends State { Expanded(child: Container()), GestureDetector( onTap: () { - saveData(); - Navigator.of(context).pop(); + final success = saveData(); + if (success) { + Navigator.of(context).pop(); + } }, child: Text( widget.isNewGoal ? 'Create' : 'Save',