From f8928a940304af0c5a0530fb0c278025dfdc7a6b Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 12:31:42 +1000 Subject: [PATCH] Feature: Allow specifying a custom DateTimeFieldCreator in the DateTimeField --- lib/src/field.dart | 20 ++++++++++++++++++++ lib/src/form_field.dart | 3 ++- pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/src/field.dart b/lib/src/field.dart index a7a45b6..13c4c46 100644 --- a/lib/src/field.dart +++ b/lib/src/field.dart @@ -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? 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, diff --git a/lib/src/form_field.dart b/lib/src/form_field.dart index 5b89d45..b4fec16 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, + DateTimeFieldCreator fieldCreator = DateTimeField.new, }) : super( key: key, initialValue: initialValue, @@ -53,7 +54,7 @@ class DateTimeFormField extends FormField { field.didChange(value); } - return DateTimeField( + return fieldCreator( firstDate: firstDate, initialDate: initialDate, lastDate: lastDate, diff --git a/pubspec.yaml b/pubspec.yaml index a5efcdb..3924b3e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: