support for providing a different initial time mode
This commit is contained in:
parent
4c4a08a5b3
commit
f843d7034a
2 changed files with 14 additions and 5 deletions
|
@ -24,6 +24,7 @@ typedef DateTimeFieldCreator = DateTimeField Function({
|
||||||
DateTime? lastDate,
|
DateTime? lastDate,
|
||||||
DateTimeFieldPickerMode mode,
|
DateTimeFieldPickerMode mode,
|
||||||
bool use24hFormat,
|
bool use24hFormat,
|
||||||
|
TimePickerEntryMode initialTimePickerEntryMode,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// [DateTimeField]
|
/// [DateTimeField]
|
||||||
|
@ -47,6 +48,7 @@ class DateTimeField extends StatelessWidget {
|
||||||
DateTime? firstDate,
|
DateTime? firstDate,
|
||||||
DateTime? lastDate,
|
DateTime? lastDate,
|
||||||
DateFormat? dateFormat,
|
DateFormat? dateFormat,
|
||||||
|
this.initialTimePickerEntryMode = TimePickerEntryMode.dial,
|
||||||
}) : dateFormat = dateFormat ?? getDateFormatFromDateFieldPickerMode(mode),
|
}) : dateFormat = dateFormat ?? getDateFormatFromDateFieldPickerMode(mode),
|
||||||
firstDate = firstDate ?? _kDefaultFirstSelectableDate,
|
firstDate = firstDate ?? _kDefaultFirstSelectableDate,
|
||||||
lastDate = lastDate ?? _kDefaultLastSelectableDate,
|
lastDate = lastDate ?? _kDefaultLastSelectableDate,
|
||||||
|
@ -62,6 +64,7 @@ class DateTimeField extends StatelessWidget {
|
||||||
this.dateTextStyle,
|
this.dateTextStyle,
|
||||||
this.use24hFormat = false,
|
this.use24hFormat = false,
|
||||||
this.initialEntryMode = DatePickerEntryMode.calendar,
|
this.initialEntryMode = DatePickerEntryMode.calendar,
|
||||||
|
this.initialTimePickerEntryMode = TimePickerEntryMode.dial,
|
||||||
DateTime? firstDate,
|
DateTime? firstDate,
|
||||||
DateTime? lastDate,
|
DateTime? lastDate,
|
||||||
}) : initialDatePickerMode = null,
|
}) : initialDatePickerMode = null,
|
||||||
|
@ -110,6 +113,9 @@ class DateTimeField extends StatelessWidget {
|
||||||
/// The initial entry mode for the material date picker dialog
|
/// The initial entry mode for the material date picker dialog
|
||||||
final DatePickerEntryMode initialEntryMode;
|
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 !
|
/// Shows a dialog asking the user to pick a date !
|
||||||
Future<void> _selectDate(BuildContext context) async {
|
Future<void> _selectDate(BuildContext context) async {
|
||||||
final DateTime initialDateTime;
|
final DateTime initialDateTime;
|
||||||
|
@ -158,8 +164,9 @@ class DateTimeField extends StatelessWidget {
|
||||||
];
|
];
|
||||||
|
|
||||||
if (modesWithTime.contains(mode)) {
|
if (modesWithTime.contains(mode)) {
|
||||||
final TimeOfDay? _selectedTime =
|
final TimeOfDay? _selectedTime = await showMaterialTimePicker(
|
||||||
await showMaterialTimePicker(context, initialDateTime);
|
context, initialDateTime,
|
||||||
|
initialEntryMode: initialTimePickerEntryMode);
|
||||||
|
|
||||||
if (_selectedTime != null) {
|
if (_selectedTime != null) {
|
||||||
_selectedDateTime = DateTime(
|
_selectedDateTime = DateTime(
|
||||||
|
@ -179,12 +186,12 @@ class DateTimeField extends StatelessWidget {
|
||||||
/// Launches the Material time picker by invoking [showTimePicker].
|
/// Launches the Material time picker by invoking [showTimePicker].
|
||||||
/// Can be @[override]n to allow further customization of the picker options
|
/// Can be @[override]n to allow further customization of the picker options
|
||||||
Future<TimeOfDay?> showMaterialTimePicker(
|
Future<TimeOfDay?> showMaterialTimePicker(
|
||||||
BuildContext context,
|
BuildContext context, DateTime initialDateTime,
|
||||||
DateTime initialDateTime,
|
{TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial}) async {
|
||||||
) async {
|
|
||||||
return showTimePicker(
|
return showTimePicker(
|
||||||
initialTime: TimeOfDay.fromDateTime(initialDateTime),
|
initialTime: TimeOfDay.fromDateTime(initialDateTime),
|
||||||
context: context,
|
context: context,
|
||||||
|
initialEntryMode: initialEntryMode,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQuery.of(context).copyWith(
|
data: MediaQuery.of(context).copyWith(
|
||||||
|
|
|
@ -30,6 +30,7 @@ class DateTimeFormField extends FormField<DateTime> {
|
||||||
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
|
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
|
||||||
DatePickerMode initialDatePickerMode = DatePickerMode.day,
|
DatePickerMode initialDatePickerMode = DatePickerMode.day,
|
||||||
DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
|
DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
|
||||||
|
TimePickerEntryMode initialTimePickerEntryMode = TimePickerEntryMode.dial,
|
||||||
DateTimeFieldCreator fieldCreator = DateTimeField.new,
|
DateTimeFieldCreator fieldCreator = DateTimeField.new,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
|
@ -68,6 +69,7 @@ class DateTimeFormField extends FormField<DateTime> {
|
||||||
mode: mode,
|
mode: mode,
|
||||||
initialEntryMode: initialEntryMode,
|
initialEntryMode: initialEntryMode,
|
||||||
dateTextStyle: dateTextStyle,
|
dateTextStyle: dateTextStyle,
|
||||||
|
initialTimePickerEntryMode: initialTimePickerEntryMode,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue