fix: pass initial day to weekday selection to prevent resetting to monday

The widget is rebuild when you come back from the weekoverview to the edit page so the previous selected day should stay on the same day
This commit is contained in:
Freek van de Ven 2024-07-26 10:55:53 +02:00 committed by FlutterJoey
parent 51fa3588be
commit 5eda42c9dd
2 changed files with 10 additions and 2 deletions

View file

@ -182,7 +182,10 @@ class _WeekTemplateModificationScreenState
const SizedBox(height: 24),
Padding(
padding: EdgeInsets.only(left: spacing.sidePadding),
child: TemplateWeekDaySelection(onDaySelected: onDaySelected),
child: TemplateWeekDaySelection(
initialSelectedDay: _selectedDay.index,
onDaySelected: onDaySelected,
),
),
const SizedBox(height: 24),
_WeekTemplateSidePadding(

View file

@ -9,9 +9,14 @@ class TemplateWeekDaySelection extends StatefulWidget {
/// Creates a [TemplateWeekDaySelection]
const TemplateWeekDaySelection({
required this.onDaySelected,
required this.initialSelectedDay,
super.key,
});
/// The initial day that should be selected when the widget is first created
/// This should be an index of the days of the week starting with 0 for Monday
final int initialSelectedDay;
/// Callback for when a day is selected
final void Function(int) onDaySelected;
@ -21,7 +26,7 @@ class TemplateWeekDaySelection extends StatefulWidget {
}
class _TemplateWeekDaySelectionState extends State<TemplateWeekDaySelection> {
int _selectedDayIndex = 0;
late int _selectedDayIndex = widget.initialSelectedDay;
@override
Widget build(BuildContext context) {