How to show the flutter timepicker in 12 hours format with AM PM selector

6,525

Solution 1

This should show you what you want

RaisedButton(
  child: Text('Show Time Picker'),
  onPressed: () async => await showTimePicker(
    context: context,
    builder: (BuildContext context, Widget child) {
      return MediaQuery(
        data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
        child: child,
      );
    },
  ),
),

Solution 2

just use format() method to get AM,PM what you required.

final TimeOfDay picked = await showTimePicker(
  context: context,
  initialTime: timeStart,
);
print(picked.format(context));    // 8:15 PM
Share:
6,525
Admin
Author by

Admin

Updated on December 19, 2022

Comments

  • Admin
    Admin over 1 year

    I want to use the Flutter timepicker in 12 hour format with AM/PM selector, but Flutter only shows me the 24 hours format.

    I want to get this format: enter image description here

    But flutter only shows me this format: enter image description here

    This is my code:

    _selectTime(BuildContext context) async {
      TimeOfDay picked = await showTimePicker(
        context: context,
        initialTime: TimeOfDay(hour: 12, minute: 00),
        builder: (BuildContext context, Widget child) {
          return MediaQuery(
            data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
            child: child,
          );
        },
      );
    }
    
  • Fabio
    Fabio over 3 years
    The source code of this answer is similar to the original one. I have tried but do not work.