mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
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:
parent
05af323aa5
commit
af42ba74ac
2 changed files with 10 additions and 2 deletions
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue