Ask Your Question
2

How can I set the Flutter Time Picker to show only AM times?

asked 2022-12-24 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-19 16:00:00 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-12-24 11:00:00 +0000

Seen: 20 times

Last updated: Apr 19 '21