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
parent 05af323aa5
commit af42ba74ac
2 changed files with 10 additions and 2 deletions

View file

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

View file

@ -9,9 +9,14 @@ class TemplateWeekDaySelection extends StatefulWidget {
/// Creates a [TemplateWeekDaySelection] /// Creates a [TemplateWeekDaySelection]
const TemplateWeekDaySelection({ const TemplateWeekDaySelection({
required this.onDaySelected, required this.onDaySelected,
required this.initialSelectedDay,
super.key, 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 /// Callback for when a day is selected
final void Function(int) onDaySelected; final void Function(int) onDaySelected;
@ -21,7 +26,7 @@ class TemplateWeekDaySelection extends StatefulWidget {
} }
class _TemplateWeekDaySelectionState extends State<TemplateWeekDaySelection> { class _TemplateWeekDaySelectionState extends State<TemplateWeekDaySelection> {
int _selectedDayIndex = 0; late int _selectedDayIndex = widget.initialSelectedDay;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {