1 | initial version |
You can set the Flutter Time Picker to show only AM times by adding the initialTime
and selectableTimePredicate
parameters to the showTimePicker()
method.
showTimePicker(
context: context,
initialTime: TimeOfDay(hour: 8, minute: 0), // Set the initial time to AM
selectableTimePredicate: (TimeOfDay time) {
// Allow times between 12:00 AM and 11:59 AM
return time.hour >= 0 && time.hour < 12;
},
);
The initialTime
parameter sets the initial time for the Time Picker to display. In this case, it is set to 8:00 AM.
The selectableTimePredicate
parameter defines which times should be selectable by the user. We are allowing times between 12:00 AM and 11:59 AM by checking if the time's hour is between 0 and 11. This prevents the Time Picker from displaying any PM times.