pickDateTime static method
Future<DateTime?>
pickDateTime({
- required BuildContext context,
- DateTime? initialDateTime,
- DateTime? firstDate,
- DateTime? lastDate,
- PickerStyle style = PickerStyle.platform,
- bool use24hFormat = true,
- Color? backgroundColor,
- Color? accentColor,
Implementation
static Future<DateTime?> pickDateTime({
required BuildContext context,
DateTime? initialDateTime,
DateTime? firstDate,
DateTime? lastDate,
PickerStyle style = PickerStyle.platform,
bool use24hFormat = true,
Color? backgroundColor,
Color? accentColor,
}) async {
final PickerStyle pickerStyle = _resolveStyle(context, style);
if (pickerStyle == PickerStyle.ios) {
return _cupertinoPicker(
context: context,
initialDate: initialDateTime ?? DateTime.now(),
mode: CupertinoDatePickerMode.dateAndTime,
use24hFormat: use24hFormat,
minimumDate: firstDate,
maximumDate: lastDate,
backgroundColor: backgroundColor,
accentColor: accentColor,
);
}
final DateTime? date = await pickDate(
context: context,
initialDate: initialDateTime,
firstDate: firstDate,
lastDate: lastDate,
style: pickerStyle,
backgroundColor: backgroundColor,
accentColor: accentColor,
);
if (date == null || !context.mounted) return null;
final TimeOfDay? time = await pickTime(
context: context,
initialTime: TimeOfDay.fromDateTime(initialDateTime ?? DateTime.now()),
style: pickerStyle,
use24hFormat: use24hFormat,
backgroundColor: backgroundColor,
accentColor: accentColor,
);
if (time == null) return null;
return DateTime(date.year, date.month, date.day, time.hour, time.minute);
}