Formatting with dart-fm

This commit is contained in:
Gaspard Merten 2020-07-15 18:55:02 +02:00
parent c520484ef8
commit 97da6f5955
3 changed files with 71 additions and 70 deletions

View file

@ -28,3 +28,7 @@
## 0.2.1 ## 0.2.1
* Adding support for Flutter web * Adding support for Flutter web
## 0.2.2
* Auto-formatting with dart-fm to meet pub.dev requirements

View file

@ -12,9 +12,8 @@ import 'package:intl/intl.dart';
/// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to /// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to
/// save or reset the form field. /// save or reset the form field.
class DateFormField extends FormField<DateTime> { class DateFormField extends FormField<DateTime> {
DateFormField(
DateFormField({ {Key key,
Key key,
FormFieldSetter<DateTime> onSaved, FormFieldSetter<DateTime> onSaved,
FormFieldValidator<DateTime> validator, FormFieldValidator<DateTime> validator,
DateTime initialValue, DateTime initialValue,
@ -26,8 +25,8 @@ class DateFormField extends FormField<DateTime> {
this.label = 'Select date', this.label = 'Select date',
this.dateFormat, this.dateFormat,
this.decoration, this.decoration,
this.initialDatePickerMode = DatePickerMode.day this.initialDatePickerMode = DatePickerMode.day})
}) : super( : super(
key: key, key: key,
initialValue: initialValue, initialValue: initialValue,
onSaved: onSaved, onSaved: onSaved,
@ -43,6 +42,7 @@ class DateFormField extends FormField<DateTime> {
} }
field.didChange(value); field.didChange(value);
} }
return DateField( return DateField(
label: label, label: label,
firstDate: firstDate, firstDate: firstDate,
@ -80,7 +80,6 @@ class DateFormField extends FormField<DateTime> {
/// (optional) Let you choose the [DatePickerMode] for the date picker! (default is [DatePickerMode.day] /// (optional) Let you choose the [DatePickerMode] for the date picker! (default is [DatePickerMode.day]
final DatePickerMode initialDatePickerMode; final DatePickerMode initialDatePickerMode;
@override @override
_DateFormFieldState createState() => _DateFormFieldState(); _DateFormFieldState createState() => _DateFormFieldState();
} }
@ -92,7 +91,6 @@ class _DateFormFieldState extends FormFieldState<DateTime> {}
/// Shows an [_InputDropdown] that'll trigger [DateField._selectDate] whenever the user /// 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, ...) /// clicks on it ! The date picker is **platform responsive** (ios date picker style for ios, ...)
class DateField extends StatelessWidget { class DateField extends StatelessWidget {
/// Default constructor /// Default constructor
const DateField({ const DateField({
@required this.onDateSelected, @required this.onDateSelected,
@ -155,9 +153,7 @@ class DateField extends StatelessWidget {
); );
}, },
); );
} } else {
else {
final DateTime _selectedDate = await showDatePicker( final DateTime _selectedDate = await showDatePicker(
context: context, context: context,
initialDatePickerMode: initialDatePickerMode, initialDatePickerMode: initialDatePickerMode,
@ -183,9 +179,11 @@ class DateField extends StatelessWidget {
label: text == null ? null : label, label: text == null ? null : label,
errorText: errorText, errorText: errorText,
decoration: decoration, decoration: decoration,
onPressed: enabled ? () { onPressed: enabled
? () {
_selectDate(context); _selectDate(context);
} : null, }
: null,
); );
} }
} }
@ -197,16 +195,15 @@ class DateField extends StatelessWidget {
/// It does not show any popup menu, it'll just trigger onPressed whenever the /// It does not show any popup menu, it'll just trigger onPressed whenever the
/// user does click on it ! /// user does click on it !
class _InputDropdown extends StatelessWidget { class _InputDropdown extends StatelessWidget {
const _InputDropdown( const _InputDropdown({
{Key key, Key key,
@required this.text, @required this.text,
this.label, this.label,
this.decoration, this.decoration,
this.textStyle, this.textStyle,
this.onPressed, this.onPressed,
this.errorText, this.errorText,
}) : }) : assert(text != null),
assert(text != null),
super(key: key); super(key: key);
/// The label to display for the field (default is 'Select date') /// The label to display for the field (default is 'Select date')
@ -235,9 +232,9 @@ class _InputDropdown extends StatelessWidget {
inkwellBorderRadius = BorderRadius.circular(8); inkwellBorderRadius = BorderRadius.circular(8);
} }
final InputDecoration effectiveDecoration = decoration?.copyWith( final InputDecoration effectiveDecoration =
errorText: errorText decoration?.copyWith(errorText: errorText) ??
) ?? InputDecoration( InputDecoration(
labelText: label, labelText: label,
errorText: errorText, errorText: errorText,
suffixIcon: Icon(Icons.arrow_drop_down), suffixIcon: Icon(Icons.arrow_drop_down),

View file

@ -1,6 +1,6 @@
name: date_field name: date_field
description: Contains DateField and DateFormField which allows the user to pick a DateTime from an input 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' homepage: 'https://github.com/GaspardMerten/date_field'
environment: environment: