Fix editing plan

This commit is contained in:
Brandon Presley 2023-11-29 16:58:40 +13:00
parent 98991a3d02
commit dac65c8390

View File

@ -103,10 +103,24 @@ class _EditPlanPageState extends State<EditPlanPage> {
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
final days = [];
for (int i = 0; i < daySelections!.length; i++) {
if (daySelections![i]) days.add(weekdayNames[i]);
}
final exercises = [];
for (int i = 0; i < exerciseSelections!.length; i++) {
if (exerciseSelections![i]) exercises.add(names[i]);
}
final newPlan = plan.copyWith(
days: Value(days.join(',')),
exercises: Value(exercises.join(',')));
if (plan.id.present)
await db.update(db.plans).replace(plan);
await db.update(db.plans).replace(newPlan);
else
await db.into(db.plans).insert(plan);
await db.into(db.plans).insert(newPlan);
if (!mounted) return;
Navigator.pop(context);
},