timePicker static method
dynamic
timePicker({
- required BuildContext context,
- required dynamic onSelected(
- String time
- String? time,
- String? minTime,
- String? maxTime,
- bool format12Hours = false,
- bool hasSeconds = false,
- TimePickerEntryMode timePickerEntryMode = TimePickerEntryMode.dial,
pick time with customization
time HH:mm:ss
Implementation
static timePicker(
{required BuildContext context,
required Function(String time) onSelected,
String? time,
String? minTime,
String? maxTime,
bool format12Hours = false,
bool hasSeconds = false,
TimePickerEntryMode timePickerEntryMode = TimePickerEntryMode.dial}) {
showTimePicker(
context: context,
initialTime: stringToTimeOfDay(time: time),
initialEntryMode: timePickerEntryMode,
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat: !format12Hours,
),
child: Localizations.override(
context: context,
locale: const Locale('en', 'US'),
child: child ?? Container(),
),
);
}).then((value) {
String selectedTime = "";
if (value != null) {
selectedTime = timeOfDayToString(time: value, hasSeconds: hasSeconds);
} else {
selectedTime = _isNullOrEmpty(time)
? ""
: hasSeconds
? time!
: timeOfDayToString(
time: stringToTimeOfDay(time: time),
hasSeconds: hasSeconds);
}
onSelected(selectedTime);
});
}