From 362f06736176c88cd206ca2c04d87ef87202062b Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 11:25:47 +1000 Subject: [PATCH 1/8] Chore: Remove pubspec.lock from repo --- .gitignore | 2 + example/pubspec.lock | 167 ------------------------------------------- pubspec.lock | 71 ------------------ 3 files changed, 2 insertions(+), 238 deletions(-) delete mode 100644 example/pubspec.lock delete mode 100644 pubspec.lock diff --git a/.gitignore b/.gitignore index bb431f0..e89bb2a 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,8 @@ .pub-cache/ .pub/ build/ +pubspec.lock +**/pubspec.lock # Android related **/android/**/gradle-wrapper.jar diff --git a/example/pubspec.lock b/example/pubspec.lock deleted file mode 100644 index 84d66c5..0000000 --- a/example/pubspec.lock +++ /dev/null @@ -1,167 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.5.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" - date_field: - dependency: "direct dev" - description: - path: ".." - relative: true - source: path - version: "1.0.5" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" -sdks: - dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index e680b3d..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,71 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - intl: - dependency: "direct main" - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.1" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" -sdks: - dart: ">=2.14.0 <3.0.0" From 32fee5da39b3f56c12c9c5768151d5e34c7d5c71 Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 11:26:53 +1000 Subject: [PATCH 2/8] Style: Remove unused import --- lib/src/form_field.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/form_field.dart b/lib/src/form_field.dart index bae689a..5b89d45 100644 --- a/lib/src/form_field.dart +++ b/lib/src/form_field.dart @@ -1,5 +1,4 @@ import 'package:date_field/src/field.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; From f9d16e3a0be30fa18f13cbc1c3807f25821d4525 Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 11:54:55 +1000 Subject: [PATCH 3/8] Feature: Extract Material Date and Time Pickers into separate methods --- lib/src/field.dart | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/lib/src/field.dart b/lib/src/field.dart index 681630c..9e5c144 100644 --- a/lib/src/field.dart +++ b/lib/src/field.dart @@ -132,14 +132,8 @@ class DateTimeField extends StatelessWidget { ]; if (modesWithDate.contains(mode)) { - final DateTime? _selectedDate = await showDatePicker( - context: context, - initialDatePickerMode: initialDatePickerMode!, - initialDate: initialDateTime, - initialEntryMode: initialEntryMode, - firstDate: firstDate, - lastDate: lastDate, - ); + final DateTime? _selectedDate = + await showMaterialDatePicker(context, initialDateTime); if (_selectedDate != null) { _selectedDateTime = _selectedDate; @@ -155,10 +149,8 @@ class DateTimeField extends StatelessWidget { ]; if (modesWithTime.contains(mode)) { - final TimeOfDay? _selectedTime = await showTimePicker( - initialTime: TimeOfDay.fromDateTime(initialDateTime), - context: context, - ); + final TimeOfDay? _selectedTime = + await showMaterialTimePicker(context, initialDateTime); if (_selectedTime != null) { _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 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 showMaterialDatePicker( + BuildContext context, + DateTime initialDateTime, + ) { + return showDatePicker( + context: context, + initialDatePickerMode: initialDatePickerMode!, + initialDate: initialDateTime, + initialEntryMode: initialEntryMode, + firstDate: firstDate, + lastDate: lastDate, + ); + } + @override Widget build(BuildContext context) { String? text; From 6b01c427b80b3a378bb6866ec08e0bf2bd06e703 Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 12:06:00 +1000 Subject: [PATCH 4/8] Feature: Extract CupertinoDatePicker into an Overrideable Method --- lib/src/field.dart | 51 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/lib/src/field.dart b/lib/src/field.dart index 9e5c144..a7a45b6 100644 --- a/lib/src/field.dart +++ b/lib/src/field.dart @@ -5,7 +5,7 @@ import 'package:intl/intl.dart'; final DateTime _kDefaultFirstSelectableDate = DateTime(1900); final DateTime _kDefaultLastSelectableDate = DateTime(2100); -const double _kCupertinoDatePickerHeight = 216; +const double kCupertinoDatePickerHeight = 216; /// [DateTimeField] /// @@ -106,22 +106,11 @@ class DateTimeField extends StatelessWidget { } if (Theme.of(context).platform == TargetPlatform.iOS) { - showModalBottomSheet( - context: context, - builder: (BuildContext builder) { - return SizedBox( - height: _kCupertinoDatePickerHeight, - child: CupertinoDatePicker( - mode: _cupertinoModeFromPickerMode(mode), - onDateTimeChanged: onDateSelected!, - initialDateTime: initialDateTime, - minimumDate: firstDate, - maximumDate: lastDate, - use24hFormat: use24hFormat, - ), - ); - }, - ); + final DateTime? _selectedDateTime = + await showCupertinoPicker(context, initialDateTime); + if (_selectedDateTime != null) { + onDateSelected!(_selectedDateTime); + } } else { DateTime _selectedDateTime = initialDateTime; @@ -195,6 +184,32 @@ class DateTimeField extends StatelessWidget { ); } + /// Launches the [CupertinoDatePicker] within a [showModalBottomSheet]. + /// Can be @[override]n to allow further customization of the picker options + Future showCupertinoPicker( + BuildContext context, + DateTime initialDateTime, + ) async { + DateTime? pickedDate; + await showModalBottomSheet( + context: context, + builder: (BuildContext builder) { + return SizedBox( + height: kCupertinoDatePickerHeight, + child: CupertinoDatePicker( + mode: cupertinoModeFromPickerMode(mode), + onDateTimeChanged: (DateTime dt) => pickedDate = dt, + initialDateTime: initialDateTime, + minimumDate: firstDate, + maximumDate: lastDate, + use24hFormat: use24hFormat, + ), + ); + }, + ); + return pickedDate; + } + @override Widget build(BuildContext context) { String? text; @@ -223,7 +238,7 @@ enum DateTimeFieldPickerMode { time, date, dateAndTime } /// Returns the [CupertinoDatePickerMode] corresponding to the selected /// [DateTimeFieldPickerMode]. This exists to prevent redundancy in the [DateTimeField] /// widget parameters. -CupertinoDatePickerMode _cupertinoModeFromPickerMode( +CupertinoDatePickerMode cupertinoModeFromPickerMode( DateTimeFieldPickerMode mode) { switch (mode) { case DateTimeFieldPickerMode.time: From f8928a940304af0c5a0530fb0c278025dfdc7a6b Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 12:31:42 +1000 Subject: [PATCH 5/8] 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: From 3896697239cebd0dc90bba58465aa89813d450cd Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 12:35:11 +1000 Subject: [PATCH 6/8] Chore: Update Changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d35f04..65f54df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +##3.0.0 + +* Breaking Upgraded minimum Dart version to 2.15 for Constructor Tearoff support +* Added optional `DateTimeFieldCreator` argument to `DateTimeFormField` to allow specifying custom implementations of `DateTimeField` +* Refactored `DateTimeField` to expose `showMaterialTimePicker`, `showMaterialDatePicker`, and `showMaterialTimePicker` as separate overrideable methods +* Made `kCupertinoDatePickerHeight` and `cupertinoModeFromPickerMode` public for convenience + ##2.1.3 * [TheGlorySaint](https://github.com/TheGlorySaint) added the possibility to use the 24Hour Format at the Timepicker. Default it is set to false From 40e788ea21083eb7200516420c2be9e111d4f16b Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 12:35:21 +1000 Subject: [PATCH 7/8] Chore: Bump Version 3.0.0 --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 3924b3e..b38bf3f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: date_field description: A widget in the form of a field that lets people choose a date, a time or both. -version: 2.1.3 -homepage: 'https://github.com/GaspardMerten/date_field' +version: 3.0.0 +homepage: 'https://github.com/axrs/date_field' environment: sdk: '>=2.15.0 <3.0.0' From e6267a13bea97b41e05cf4aaf3a586b6445e1663 Mon Sep 17 00:00:00 2001 From: Alexander Scott Date: Sat, 26 Feb 2022 12:37:15 +1000 Subject: [PATCH 8/8] Chore: Bump Readme Version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd4ed6f..f5829db 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency: ```yaml dependencies: ... - date_field: ^2.1.2 + date_field: ^3.0.0 ``` In your library add the following import: