From f843d7034ab032fa52288fdc540c698cb10a14d8 Mon Sep 17 00:00:00 2001 From: schalky Date: Tue, 29 Nov 2022 20:09:40 -0800 Subject: [PATCH] support for providing a different initial time mode --- lib/src/field.dart | 17 ++++++++++++----- lib/src/form_field.dart | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/field.dart b/lib/src/field.dart index d9adfb8..2511fb6 100644 --- a/lib/src/field.dart +++ b/lib/src/field.dart @@ -24,6 +24,7 @@ typedef DateTimeFieldCreator = DateTimeField Function({ DateTime? lastDate, DateTimeFieldPickerMode mode, bool use24hFormat, + TimePickerEntryMode initialTimePickerEntryMode, }); /// [DateTimeField] @@ -47,6 +48,7 @@ class DateTimeField extends StatelessWidget { DateTime? firstDate, DateTime? lastDate, DateFormat? dateFormat, + this.initialTimePickerEntryMode = TimePickerEntryMode.dial, }) : dateFormat = dateFormat ?? getDateFormatFromDateFieldPickerMode(mode), firstDate = firstDate ?? _kDefaultFirstSelectableDate, lastDate = lastDate ?? _kDefaultLastSelectableDate, @@ -62,6 +64,7 @@ class DateTimeField extends StatelessWidget { this.dateTextStyle, this.use24hFormat = false, this.initialEntryMode = DatePickerEntryMode.calendar, + this.initialTimePickerEntryMode = TimePickerEntryMode.dial, DateTime? firstDate, DateTime? lastDate, }) : initialDatePickerMode = null, @@ -110,6 +113,9 @@ class DateTimeField extends StatelessWidget { /// The initial entry mode for the material date picker dialog final DatePickerEntryMode initialEntryMode; + // the initial entry mode for the material time picker dialog + final TimePickerEntryMode initialTimePickerEntryMode; + /// Shows a dialog asking the user to pick a date ! Future _selectDate(BuildContext context) async { final DateTime initialDateTime; @@ -158,8 +164,9 @@ class DateTimeField extends StatelessWidget { ]; if (modesWithTime.contains(mode)) { - final TimeOfDay? _selectedTime = - await showMaterialTimePicker(context, initialDateTime); + final TimeOfDay? _selectedTime = await showMaterialTimePicker( + context, initialDateTime, + initialEntryMode: initialTimePickerEntryMode); if (_selectedTime != null) { _selectedDateTime = DateTime( @@ -179,12 +186,12 @@ 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 showMaterialTimePicker( - BuildContext context, - DateTime initialDateTime, - ) async { + BuildContext context, DateTime initialDateTime, + {TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial}) async { return showTimePicker( initialTime: TimeOfDay.fromDateTime(initialDateTime), context: context, + initialEntryMode: initialEntryMode, builder: (BuildContext context, Widget? child) { return MediaQuery( data: MediaQuery.of(context).copyWith( diff --git a/lib/src/form_field.dart b/lib/src/form_field.dart index d11a4ff..93770d8 100644 --- a/lib/src/form_field.dart +++ b/lib/src/form_field.dart @@ -30,6 +30,7 @@ class DateTimeFormField extends FormField { DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar, DatePickerMode initialDatePickerMode = DatePickerMode.day, DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime, + TimePickerEntryMode initialTimePickerEntryMode = TimePickerEntryMode.dial, DateTimeFieldCreator fieldCreator = DateTimeField.new, }) : super( key: key, @@ -68,6 +69,7 @@ class DateTimeFormField extends FormField { mode: mode, initialEntryMode: initialEntryMode, dateTextStyle: dateTextStyle, + initialTimePickerEntryMode: initialTimePickerEntryMode, ); }, );