selectDateTime function
- BuildContext context
Select a date and time with the date picker and time picker.
Implementation
Future<DateTime?> selectDateTime(
BuildContext context,
) async {
return showDatePicker(
locale: const Locale("en", "GB"),
context: context,
cancelText: t.generics.cancel,
confirmText: t.generics.OK,
helpText: t.time.pickDate,
initialDate: DateTime.now(),
firstDate: DateTime(2021),
lastDate: DateTime(2101),
).then((date) {
if (date == null) return null;
return showTimePicker(
context: context,
cancelText: t.generics.cancel,
confirmText: t.generics.OK,
helpText: t.time.pickTime,
initialTime: const TimeOfDay(hour: 12, minute: 0),
).then((time) {
if (time == null) return null;
return DateTime(date.year, date.month, date.day, time.hour, time.minute);
});
});
}