Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting minutes in time pickers #616

Merged
merged 3 commits into from
Apr 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions app/lib/timetable/src/edit_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ Future<Time> selectTime(BuildContext context,
await cache.isTimePickerWithFifeMinutesIntervalActiveStream().first ??
true;

minutesInterval ??= isFiveMinutesIntervalActive ? 5 : 1;

if (PlatformCheck.isIOS) {
return showDialog<TimeOfDay>(
context: context,
builder: (context) => CupertinoTimerPickerWithTimeOfDay(
initalTime: initialTime?.toTimeOfDay(),
minutesInterval:
minutesInterval ?? (isFiveMinutesIntervalActive ? 5 : 1),
minutesInterval: minutesInterval,
title: title,
),
).then((timeOfDay) {
Expand All @@ -114,8 +115,8 @@ Future<Time> selectTime(BuildContext context,
return showIntervalTimePicker(
context: context,
initialTime: initialTime?.toTimeOfDay() ?? TimeOfDay(hour: 9, minute: 10),
interval: 30,
visibleStep: VisibleStep.thirtieths,
interval: minutesInterval,
visibleStep: minutesInterval.toVisibleStep(),
builder: (BuildContext context, Widget child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
Expand Down Expand Up @@ -205,3 +206,29 @@ class _CupertinoTimerPickerWithTimeOfDayState
return TimeOfDay(hour: hours, minute: minutes);
}
}

extension on int {
VisibleStep toVisibleStep() {
switch (this) {
case 1:
case 5:
return VisibleStep.fifths;
case 6:
return VisibleStep.sixths;
case 10:
return VisibleStep.tenths;
case 20:
return VisibleStep.twentieths;
case 30:
return VisibleStep.thirtieths;
case 60:
return VisibleStep.sixtieth;
default:
// At the moment, only these intervals are supported. If you need
// another one, please add it and handle it in the switch statement.
throw Exception(
"Unsupported minutes interval: $this. Please handle the other cases yourself.",
);
}
}
}