From 97da6f59556696480e7ecd6abc257eba34d74eb6 Mon Sep 17 00:00:00 2001 From: Gaspard Merten Date: Wed, 15 Jul 2020 18:55:02 +0200 Subject: [PATCH] Formatting with dart-fm --- CHANGELOG.md | 6 +- lib/date_field.dart | 133 ++++++++++++++++++++++---------------------- pubspec.yaml | 2 +- 3 files changed, 71 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ba2ad..1721be3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,4 +27,8 @@ ## 0.2.1 -* Adding support for Flutter web \ No newline at end of file +* Adding support for Flutter web + +## 0.2.2 + +* Auto-formatting with dart-fm to meet pub.dev requirements \ No newline at end of file diff --git a/lib/date_field.dart b/lib/date_field.dart index 46a4716..86b4cde 100644 --- a/lib/date_field.dart +++ b/lib/date_field.dart @@ -12,51 +12,51 @@ import 'package:intl/intl.dart'; /// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to /// save or reset the form field. class DateFormField extends FormField { + DateFormField( + {Key key, + FormFieldSetter onSaved, + FormFieldValidator validator, + DateTime initialValue, + bool autovalidate = false, + bool enabled = true, + this.onDateSelected, + this.firstDate, + this.lastDate, + this.label = 'Select date', + this.dateFormat, + this.decoration, + this.initialDatePickerMode = DatePickerMode.day}) + : super( + key: key, + initialValue: initialValue, + onSaved: onSaved, + validator: validator, + autovalidate: autovalidate, + enabled: enabled, + builder: (FormFieldState field) { + final _DateFormFieldState state = field; - DateFormField({ - Key key, - FormFieldSetter onSaved, - FormFieldValidator validator, - DateTime initialValue, - bool autovalidate = false, - bool enabled = true, - this.onDateSelected, - this.firstDate, - this.lastDate, - this.label = 'Select date', - this.dateFormat, - this.decoration, - this.initialDatePickerMode = DatePickerMode.day - }) : super( - key: key, - initialValue: initialValue, - onSaved: onSaved, - validator: validator, - autovalidate: autovalidate, - enabled: enabled, - builder: (FormFieldState field) { - final _DateFormFieldState state = field; + void onChangedHandler(DateTime value) { + if (onDateSelected != null) { + onDateSelected(value); + } + field.didChange(value); + } - void onChangedHandler(DateTime value) { - if (onDateSelected != null) { - onDateSelected(value); - } - field.didChange(value); - } - return DateField( - label: label, - firstDate: firstDate, - lastDate: lastDate, - decoration: decoration, - initialDatePickerMode: initialDatePickerMode, - dateFormat: dateFormat, - errorText: state.errorText, - onDateSelected: onChangedHandler, - selectedDate: state.value, - enabled: enabled, - ); - }, - ); + return DateField( + label: label, + firstDate: firstDate, + lastDate: lastDate, + decoration: decoration, + initialDatePickerMode: initialDatePickerMode, + dateFormat: dateFormat, + errorText: state.errorText, + onDateSelected: onChangedHandler, + selectedDate: state.value, + enabled: enabled, + ); + }, + ); /// (optional) A callback that will be triggered whenever a new /// DateTime is selected @@ -80,7 +80,6 @@ class DateFormField extends FormField { /// (optional) Let you choose the [DatePickerMode] for the date picker! (default is [DatePickerMode.day] final DatePickerMode initialDatePickerMode; - @override _DateFormFieldState createState() => _DateFormFieldState(); } @@ -92,7 +91,6 @@ class _DateFormFieldState extends FormFieldState {} /// Shows an [_InputDropdown] that'll trigger [DateField._selectDate] whenever the user /// clicks on it ! The date picker is **platform responsive** (ios date picker style for ios, ...) class DateField extends StatelessWidget { - /// Default constructor const DateField({ @required this.onDateSelected, @@ -155,9 +153,7 @@ class DateField extends StatelessWidget { ); }, ); - } - else { - + } else { final DateTime _selectedDate = await showDatePicker( context: context, initialDatePickerMode: initialDatePickerMode, @@ -183,9 +179,11 @@ class DateField extends StatelessWidget { label: text == null ? null : label, errorText: errorText, decoration: decoration, - onPressed: enabled ? () { - _selectDate(context); - } : null, + onPressed: enabled + ? () { + _selectDate(context); + } + : null, ); } } @@ -197,16 +195,15 @@ class DateField extends StatelessWidget { /// It does not show any popup menu, it'll just trigger onPressed whenever the /// user does click on it ! class _InputDropdown extends StatelessWidget { - const _InputDropdown( - {Key key, - @required this.text, - this.label, - this.decoration, - this.textStyle, - this.onPressed, - this.errorText, - }) : - assert(text != null), + const _InputDropdown({ + Key key, + @required this.text, + this.label, + this.decoration, + this.textStyle, + this.onPressed, + this.errorText, + }) : assert(text != null), super(key: key); /// The label to display for the field (default is 'Select date') @@ -235,13 +232,13 @@ class _InputDropdown extends StatelessWidget { inkwellBorderRadius = BorderRadius.circular(8); } - final InputDecoration effectiveDecoration = decoration?.copyWith( - errorText: errorText - ) ?? InputDecoration( - labelText: label, - errorText: errorText, - suffixIcon: Icon(Icons.arrow_drop_down), - ).applyDefaults(Theme.of(context).inputDecorationTheme); + final InputDecoration effectiveDecoration = + decoration?.copyWith(errorText: errorText) ?? + InputDecoration( + labelText: label, + errorText: errorText, + suffixIcon: Icon(Icons.arrow_drop_down), + ).applyDefaults(Theme.of(context).inputDecorationTheme); return Material( color: Colors.transparent, diff --git a/pubspec.yaml b/pubspec.yaml index bb0f996..e35e903 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: date_field description: Contains DateField and DateFormField which allows the user to pick a DateTime from an input field! -version: 0.2.1 +version: 0.2.2 homepage: 'https://github.com/GaspardMerten/date_field' environment: