From a5d30f96f27c3faa6d8e5b10ed8cda37f55fda53 Mon Sep 17 00:00:00 2001 From: Bruno D'Luka Date: Fri, 22 Nov 2024 00:33:47 -0300 Subject: [PATCH] fix: `TimePicker` hour offset --- CHANGELOG.md | 1 + lib/src/controls/form/pickers/time_picker.dart | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c497cde7..d89a6353 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - feat: Add `TabView.gestures`, which allows the manipulation of the tab gestures ([#1138](https://github.com/bdlukaa/fluent_ui/issues/1138)) - feat: Add `DropDownButton.style` ([#1139](https://github.com/bdlukaa/fluent_ui/issues/1139)) - feat: Possibility to open date and time pickers programatically ([#1142](https://github.com/bdlukaa/fluent_ui/issues/1142)) +- fix: `TimePicker` hour offset ## 4.9.2 diff --git a/lib/src/controls/form/pickers/time_picker.dart b/lib/src/controls/form/pickers/time_picker.dart index 6f7853b7..3653f2d1 100644 --- a/lib/src/controls/form/pickers/time_picker.dart +++ b/lib/src/controls/form/pickers/time_picker.dart @@ -171,7 +171,7 @@ class TimePickerState extends State WidgetsBinding.instance.addPostFrameCallback((_) { time = widget.selected ?? DateTime.now(); _hourController.jumpToItem(() { - var hour = time.hour - 1; + var hour = time.hour; if (!widget.use24Format) { hour -= 12; } @@ -193,7 +193,7 @@ class TimePickerState extends State } _hourController = FixedExtentScrollController( initialItem: () { - var hour = time.hour - 1; + var hour = time.hour; if (!widget.use24Format) { hour -= 12; } @@ -334,6 +334,8 @@ class TimePickerState extends State } } +// Since hours goes from 0 to 23, it is not needed to add 1 to the index since +// it already starts from 0. class _TimePickerContentPopup extends StatefulWidget { const _TimePickerContentPopup({ required this.date, @@ -449,8 +451,7 @@ class __TimePickerContentPopupState extends State<_TimePickerContentPopup> { child: ListWheelScrollView.useDelegate( controller: widget.hourController, childDelegate: ListWheelChildLoopingListDelegate( - children: List.generate(hoursAmount, (index) { - final hour = index + 1; + children: List.generate(hoursAmount, (hour) { final realHour = () { if (!widget.use24Format && localDate.hour > 12) { return hour + 12; @@ -464,7 +465,7 @@ class __TimePickerContentPopupState extends State<_TimePickerContentPopup> { ? null : () { widget.hourController.animateToItem( - index, + hour, duration: theme.mediumAnimationDuration, curve: theme.animationCurve, ); @@ -481,8 +482,7 @@ class __TimePickerContentPopupState extends State<_TimePickerContentPopup> { itemExtent: kOneLineTileHeight, diameterRatio: kPickerDiameterRatio, physics: const FixedExtentScrollPhysics(), - onSelectedItemChanged: (index) { - var hour = index + 1; + onSelectedItemChanged: (hour) { if (!widget.use24Format && !isAm) { hour += 12; }