From af42ba74acc89a4b71d7b559caa628e569aab84e Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Fri, 26 Jul 2024 10:55:53 +0200 Subject: [PATCH] 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 --- .../lib/src/ui/screens/template_week_modification.dart | 5 ++++- .../lib/src/ui/widgets/template_week_day_selection.dart | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/flutter_availability/lib/src/ui/screens/template_week_modification.dart b/packages/flutter_availability/lib/src/ui/screens/template_week_modification.dart index e54d562..b1ff595 100644 --- a/packages/flutter_availability/lib/src/ui/screens/template_week_modification.dart +++ b/packages/flutter_availability/lib/src/ui/screens/template_week_modification.dart @@ -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( diff --git a/packages/flutter_availability/lib/src/ui/widgets/template_week_day_selection.dart b/packages/flutter_availability/lib/src/ui/widgets/template_week_day_selection.dart index b986e30..dcbaca7 100644 --- a/packages/flutter_availability/lib/src/ui/widgets/template_week_day_selection.dart +++ b/packages/flutter_availability/lib/src/ui/widgets/template_week_day_selection.dart @@ -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 { - int _selectedDayIndex = 0; + late int _selectedDayIndex = widget.initialSelectedDay; @override Widget build(BuildContext context) {