pickTime static method
Future<TimeOfDay?>
pickTime({
- required BuildContext context,
- TimeOfDay? initialTime,
- PickerStyle style = PickerStyle.platform,
- bool use24hFormat = true,
- String doneLabel = 'Done',
- String cancelLabel = 'Cancel',
- Color? backgroundColor,
- Color? accentColor,
Implementation
static Future<TimeOfDay?> pickTime({
required BuildContext context,
TimeOfDay? initialTime,
PickerStyle style = PickerStyle.platform,
bool use24hFormat = true,
String doneLabel = 'Done',
String cancelLabel = 'Cancel',
Color? backgroundColor,
Color? accentColor,
}) async {
initialTime ??= TimeOfDay.now();
final PickerStyle pickerStyle = _resolveStyle(context, style);
if (pickerStyle == PickerStyle.ios) {
final DateTime? picked = await _cupertinoPicker(
context: context,
initialDate: DateTime(0, 1, 1, initialTime.hour, initialTime.minute),
mode: CupertinoDatePickerMode.time,
use24hFormat: use24hFormat,
doneLabel: doneLabel,
cancelLabel: cancelLabel,
backgroundColor: backgroundColor,
accentColor: accentColor,
);
return picked != null
? TimeOfDay(hour: picked.hour, minute: picked.minute)
: null;
}
return showTimePicker(
context: context,
initialTime: initialTime,
builder: (BuildContext ctx, Widget? child) =>
_applyAccent(ctx, child, accentColor),
);
}