diff --git a/lib/days.dart b/lib/days.dart new file mode 100644 index 0000000..b0cd238 --- /dev/null +++ b/lib/days.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; + +class Days extends StatefulWidget { + final ValueChanged onChanged; + + const Days({required this.onChanged, super.key}); + + @override + createState() => _DaysState(); +} + +class _DaysState extends State { + final List _selections = List.generate(7, (_) => false); + final List _days = [ + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday' + ]; + + String _getSelectedDaysString() { + List selectedDays = []; + for (int i = 0; i < _selections.length; i++) { + if (_selections[i]) { + selectedDays.add(_days[i]); + } + } + return selectedDays.join(","); + } + + void _updateSelections(int index) { + setState(() { + _selections[index] = !_selections[index]; + widget.onChanged(_getSelectedDaysString()); + }); + } + + @override + Widget build(BuildContext context) { + return Column( + children: List.generate(7, (index) { + return SwitchListTile( + title: Text(_days[index]), + value: _selections[index], + onChanged: (value) => _updateSelections(index), + ); + }), + ); + } +} diff --git a/lib/edit_plan.dart b/lib/edit_plan.dart index 4e72602..34dcfe5 100644 --- a/lib/edit_plan.dart +++ b/lib/edit_plan.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/material.dart' as material; import 'package:fmassive/database.dart'; +import 'package:fmassive/days.dart'; import 'package:fmassive/main.dart'; import 'package:moor_flutter/moor_flutter.dart'; @@ -59,20 +60,11 @@ class _EditPlanPageState extends State { child: material.Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - TextFormField( - controller: _daysController, - focusNode: daysNode, - decoration: const InputDecoration(labelText: 'Days'), - onTap: () { - _daysController.selection = TextSelection( - baseOffset: 0, extentOffset: _daysController.text.length); - }, - onChanged: (value) { - setState(() { - plan = plan.copyWith(days: Value(value)); - }); - }, - ), + Days(onChanged: (days) { + setState(() { + days = days; + }); + }), TextFormField( controller: _workoutsController, focusNode: workoutsNode,