Reputation: 87
For the showTimePicker function in Flutter used to select a time, is it possible to set a defined time interval (such as 15 minutes) to prevent users from selecting any other timing?
Currently, this is the code I have for creating a default TimePicker.
showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
Upvotes: 6
Views: 8664
Reputation: 1272
You could try using this temporal solution using: time_picker_widget
Copy the following code into this DEMO
showCustomTimePicker(
context: context,
// It is a must if you provide selectableTimePredicate
onFailValidation: (context) =>
showMessage(context, 'Unavailable selection.'),
initialTime: TimeOfDay(
hour: _availableHours.first,
minute: 0),
selectableTimePredicate: (time) =>
_availableHours.indexOf(time.hour) != -1 &&
time.minute % 15 == 0).then(
(time) =>
setState(() => selectedTime = time?.format(context))),
Upvotes: 5
Reputation: 592
There is currently no way in the API, I have raised this issue: https://github.com/flutter/flutter/issues/60573
Upvotes: 3