I have this CupertinoDatePicker set in time mode with 24h format and 15 minute interval:
CupertinoDatePicker(
use24hFormat: true,
mode: CupertinoDatePickerMode.time,
minuteInterval: 15,
initialDateTime: currentDate,
minimumDate: DateTime(currentDate.year, currentDate.month,
currentDate.day, minHours, minMinutes),
maximumDate: DateTime(currentDate.year, currentDate.month,
currentDate.day + nextDay, maxHours, maxMinutes),
onDateTimeChanged: (DateTime newDateTime) {
currentDate = newDateTime;
}
)
I set the initial date to currentDate which is defined as follows:
DateTime currentDate =
DateTime(1900, 1, 1, currentHour, currentMinute);
where currentHour and currentMinute are two variables that I pass in this function. In the function before displaying the DatePicker, I also calculate minHours, minMinutes and maxHours and maxMinutes, that should limit the range in which user can pick the hours and minutes, done by setting minimumDate and maximumDate of the Picker.
The only BIG problem is that I want to count midnight (so 00:00) as the maximum time in some cases. So for example what if I want to disable between 00:15 and 9:00 but keep 00:00 enabled??