Feature: Extract Material Date and Time Pickers into separate methods

This commit is contained in:
Alexander Scott 2022-02-26 11:54:55 +10:00
parent 32fee5da39
commit f9d16e3a0b

View file

@ -132,14 +132,8 @@ class DateTimeField extends StatelessWidget {
]; ];
if (modesWithDate.contains(mode)) { if (modesWithDate.contains(mode)) {
final DateTime? _selectedDate = await showDatePicker( final DateTime? _selectedDate =
context: context, await showMaterialDatePicker(context, initialDateTime);
initialDatePickerMode: initialDatePickerMode!,
initialDate: initialDateTime,
initialEntryMode: initialEntryMode,
firstDate: firstDate,
lastDate: lastDate,
);
if (_selectedDate != null) { if (_selectedDate != null) {
_selectedDateTime = _selectedDate; _selectedDateTime = _selectedDate;
@ -155,10 +149,8 @@ class DateTimeField extends StatelessWidget {
]; ];
if (modesWithTime.contains(mode)) { if (modesWithTime.contains(mode)) {
final TimeOfDay? _selectedTime = await showTimePicker( final TimeOfDay? _selectedTime =
initialTime: TimeOfDay.fromDateTime(initialDateTime), await showMaterialTimePicker(context, initialDateTime);
context: context,
);
if (_selectedTime != null) { if (_selectedTime != null) {
_selectedDateTime = DateTime( _selectedDateTime = DateTime(
@ -175,6 +167,34 @@ class DateTimeField extends StatelessWidget {
} }
} }
/// Launches the Material time picker by invoking [showTimePicker].
/// Can be @[override]n to allow further customization of the picker options
Future<TimeOfDay?> showMaterialTimePicker(
BuildContext context,
DateTime initialDateTime,
) async {
return showTimePicker(
initialTime: TimeOfDay.fromDateTime(initialDateTime),
context: context,
);
}
/// Launches the Material time picker by invoking [showDatePicker].
/// Can be @[override]n to allow further customization of the picker options
Future<DateTime?> showMaterialDatePicker(
BuildContext context,
DateTime initialDateTime,
) {
return showDatePicker(
context: context,
initialDatePickerMode: initialDatePickerMode!,
initialDate: initialDateTime,
initialEntryMode: initialEntryMode,
firstDate: firstDate,
lastDate: lastDate,
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String? text; String? text;