Feature: Allow specifying a custom DateTimeFieldCreator in the DateTimeField

This commit is contained in:
Alexander Scott 2022-02-26 12:31:42 +10:00
parent 6b01c427b8
commit f8928a9403
3 changed files with 23 additions and 2 deletions

View file

@ -7,11 +7,31 @@ final DateTime _kDefaultLastSelectableDate = DateTime(2100);
const double kCupertinoDatePickerHeight = 216;
/// Constructor tearoff definition that matches [DateTimeField.new]
// Note: This should match the definition of the [DateTimeField] constructor
typedef DateTimeFieldCreator = DateTimeField Function({
Key? key,
required ValueChanged<DateTime>? onDateSelected,
required DateTime? selectedDate,
DateFormat? dateFormat,
TextStyle? dateTextStyle,
InputDecoration? decoration,
bool? enabled,
DateTime? firstDate,
DateTime? initialDate,
DatePickerMode? initialDatePickerMode,
DatePickerEntryMode initialEntryMode,
DateTime? lastDate,
DateTimeFieldPickerMode mode,
bool use24hFormat,
});
/// [DateTimeField]
///
/// Shows an [_InputDropdown] that'll trigger [DateTimeField._selectDate] whenever the user
/// clicks on it ! The date picker is **platform responsive** (ios date picker style for ios, ...)
class DateTimeField extends StatelessWidget {
// Note: This should match the definition of the [DateTimeFieldCreator]
DateTimeField({
Key? key,
required this.onDateSelected,

View file

@ -30,6 +30,7 @@ class DateTimeFormField extends FormField<DateTime> {
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
DatePickerMode initialDatePickerMode = DatePickerMode.day,
DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
DateTimeFieldCreator fieldCreator = DateTimeField.new,
}) : super(
key: key,
initialValue: initialValue,
@ -53,7 +54,7 @@ class DateTimeFormField extends FormField<DateTime> {
field.didChange(value);
}
return DateTimeField(
return fieldCreator(
firstDate: firstDate,
initialDate: initialDate,
lastDate: lastDate,

View file

@ -4,7 +4,7 @@ version: 2.1.3
homepage: 'https://github.com/GaspardMerten/date_field'
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <3.0.0'
dependencies:
flutter: