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
Author by
Admin
Updated on December 19, 2022Comments
-
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:
But flutter only shows me this format:
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 over 3 yearsThe source code of this answer is similar to the original one. I have tried but do not work.