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,
);
},
);
}
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,
);
},
),
),
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With