Ensure days + exercises are selected for new plan
This commit is contained in:
parent
9aed2b3ac1
commit
8678e935df
|
@ -78,7 +78,8 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Widget> actions = [];
|
List<Widget> actions = [];
|
||||||
if (widget.plan.id.present)
|
if (widget.plan.id.present)
|
||||||
actions.add(IconButton(
|
actions.add(
|
||||||
|
IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
bool? confirm = await _showConfirmationDialog(context);
|
bool? confirm = await _showConfirmationDialog(context);
|
||||||
if (!confirm!) return;
|
if (!confirm!) return;
|
||||||
|
@ -86,7 +87,9 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.delete),),);
|
icon: const Icon(Icons.delete),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
@ -104,15 +107,28 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
for (int i = 0; i < daySelections!.length; i++) {
|
for (int i = 0; i < daySelections!.length; i++) {
|
||||||
if (daySelections![i]) days.add(weekdayNames[i]);
|
if (daySelections![i]) days.add(weekdayNames[i]);
|
||||||
}
|
}
|
||||||
|
if (days.isEmpty) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Select days first')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final exercises = [];
|
final exercises = [];
|
||||||
for (int i = 0; i < exerciseSelections!.length; i++) {
|
for (int i = 0; i < exerciseSelections!.length; i++) {
|
||||||
if (exerciseSelections![i]) exercises.add(names[i]);
|
if (exerciseSelections![i]) exercises.add(names[i]);
|
||||||
}
|
}
|
||||||
|
if (exercises.isEmpty) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Select exercises first')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var newPlan = widget.plan.copyWith(
|
var newPlan = widget.plan.copyWith(
|
||||||
days: Value(days.join(',')),
|
days: Value(days.join(',')),
|
||||||
exercises: Value(exercises.join(',')),);
|
exercises: Value(exercises.join(',')),
|
||||||
|
);
|
||||||
|
|
||||||
if (widget.plan.id.present)
|
if (widget.plan.id.present)
|
||||||
await db.update(db.plans).replace(newPlan);
|
await db.update(db.plans).replace(newPlan);
|
||||||
|
@ -126,7 +142,8 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
},
|
},
|
||||||
child: const Icon(Icons.check),
|
child: const Icon(Icons.check),
|
||||||
),
|
),
|
||||||
),);
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> get getChildren {
|
List<Widget> get getChildren {
|
||||||
|
@ -168,7 +185,8 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: children,
|
children: children,
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user