Skip to content

Commit

Permalink
fix: TimePicker hour offset
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Nov 22, 2024
1 parent b7b5eab commit a5d30f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions lib/src/controls/form/pickers/time_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TimePickerState extends State<TimePicker>
WidgetsBinding.instance.addPostFrameCallback((_) {
time = widget.selected ?? DateTime.now();
_hourController.jumpToItem(() {
var hour = time.hour - 1;
var hour = time.hour;
if (!widget.use24Format) {
hour -= 12;
}
Expand All @@ -193,7 +193,7 @@ class TimePickerState extends State<TimePicker>
}
_hourController = FixedExtentScrollController(
initialItem: () {
var hour = time.hour - 1;
var hour = time.hour;
if (!widget.use24Format) {
hour -= 12;
}
Expand Down Expand Up @@ -334,6 +334,8 @@ class TimePickerState extends State<TimePicker>
}
}

// 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,
Expand Down Expand Up @@ -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;
Expand All @@ -464,7 +465,7 @@ class __TimePickerContentPopupState extends State<_TimePickerContentPopup> {
? null
: () {
widget.hourController.animateToItem(
index,
hour,
duration: theme.mediumAnimationDuration,
curve: theme.animationCurve,
);
Expand All @@ -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;
}
Expand Down

0 comments on commit a5d30f9

Please sign in to comment.