Correctly handle navigation when adding or editing plans

This commit is contained in:
Roland Geider
2021-04-28 11:24:23 +02:00
parent b4bdec0d5a
commit 0673cbf3ce
2 changed files with 21 additions and 17 deletions

View File

@@ -230,11 +230,18 @@ class PlanForm extends StatelessWidget {
}
_form.currentState!.save();
// Save the entry on the server
// Save to DB
try {
_plan.id != null
? await Provider.of<Nutrition>(context, listen: false).editPlan(_plan)
: _plan = await Provider.of<Nutrition>(context, listen: false).addPlan(_plan);
if (_plan.id != null) {
await Provider.of<Nutrition>(context, listen: false).editPlan(_plan);
Navigator.of(context).pop();
} else {
_plan = await Provider.of<Nutrition>(context, listen: false).addPlan(_plan);
Navigator.of(context).pushReplacementNamed(
NutritionalPlanScreen.routeName,
arguments: _plan,
);
}
// Saving was successful, reset the data
_descriptionController.clear();
@@ -243,10 +250,6 @@ class PlanForm extends StatelessWidget {
} catch (error) {
showErrorDialog(error, context);
}
Navigator.of(context).pushReplacementNamed(
NutritionalPlanScreen.routeName,
arguments: _plan,
);
},
),
],

View File

@@ -80,15 +80,16 @@ class WorkoutForm extends StatelessWidget {
_form.currentState!.save();
// Save to DB
_plan.id != null
? await Provider.of<WorkoutPlans>(context, listen: false).editWorkout(_plan)
: _plan =
await Provider.of<WorkoutPlans>(context, listen: false).addWorkout(_plan);
Navigator.of(context).pushReplacementNamed(
WorkoutPlanScreen.routeName,
arguments: _plan,
);
if (_plan.id != null) {
await Provider.of<WorkoutPlans>(context, listen: false).editWorkout(_plan);
Navigator.of(context).pop();
} else {
_plan = await Provider.of<WorkoutPlans>(context, listen: false).addWorkout(_plan);
Navigator.of(context).pushReplacementNamed(
WorkoutPlanScreen.routeName,
arguments: _plan,
);
}
},
),
],