Formatting with dartfm

This commit is contained in:
Gaspard Merten 2020-03-01 23:34:26 +01:00
parent 14a4f9eff4
commit 4f27d54cc6
5 changed files with 40 additions and 27 deletions

View file

@ -1,3 +1,10 @@
## 0.0.1 ## 0.0.1
* Initial version * Initial version
## 0.0.2
* Fixing README.md
* Updating package description
* Formatting with DartFM

View file

@ -1,6 +1,6 @@
# date_field # date_field
Contains DateField and DateFormField! Contains DateField and DateFormField which allows the user to pick a DateTime from an input field!
## Getting Started ## Getting Started

View file

@ -8,18 +8,12 @@ void main() {
} }
class ExampleApp extends StatelessWidget { class ExampleApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(title: 'Example app', home: HomeWidget());
title: 'Example app',
home: HomeWidget()
);
} }
} }
class HomeWidget extends StatefulWidget { class HomeWidget extends StatefulWidget {
@override @override
_HomeWidgetState createState() => _HomeWidgetState(); _HomeWidgetState createState() => _HomeWidgetState();

View file

@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
class DateFormField extends StatelessWidget { class DateFormField extends StatelessWidget {
/// An optional method to call with the final value when the form is saved via /// An optional method to call with the final value when the form is saved via
/// [FormState.save]. /// [FormState.save].
final FormFieldSetter<DateTime> onSaved; final FormFieldSetter<DateTime> onSaved;
@ -14,7 +13,6 @@ class DateFormField extends StatelessWidget {
/// display if the input is invalid, or null otherwise. /// display if the input is invalid, or null otherwise.
final FormFieldValidator<DateTime> validator; final FormFieldValidator<DateTime> validator;
/// An optional value to initialize the form field to, or null otherwise. /// An optional value to initialize the form field to, or null otherwise.
final DateTime initialValue; final DateTime initialValue;
@ -50,7 +48,18 @@ class DateFormField extends StatelessWidget {
final DatePickerMode initialDatePickerMode; final DatePickerMode initialDatePickerMode;
const DateFormField( const DateFormField(
{Key key, this.onSaved, this.validator, this.initialValue, this.autovalidate=false, this.enabled=true, this.firstDate, this.lastDate, this.label='Select date', this.dateFormat, this.decoration, this.initialDatePickerMode}) {Key key,
this.onSaved,
this.validator,
this.initialValue,
this.autovalidate = false,
this.enabled = true,
this.firstDate,
this.lastDate,
this.label = 'Select date',
this.dateFormat,
this.decoration,
this.initialDatePickerMode})
: super(key: key); : super(key: key);
@override @override
@ -75,8 +84,7 @@ class DateFormField extends StatelessWidget {
}, },
selectedDate: state.value, selectedDate: state.value,
); );
} });
);
} }
} }
@ -136,7 +144,8 @@ class DateField extends StatelessWidget {
height: MediaQuery.of(context).size.height / 4, height: MediaQuery.of(context).size.height / 4,
child: CupertinoDatePicker( child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date, mode: CupertinoDatePickerMode.date,
onDateTimeChanged:(DateTime dateTime) => onDateSelected(dateTime), onDateTimeChanged: (DateTime dateTime) =>
onDateSelected(dateTime),
initialDateTime: selectedDate ?? lastDate ?? DateTime.now(), initialDateTime: selectedDate ?? lastDate ?? DateTime.now(),
minimumDate: firstDate, minimumDate: firstDate,
maximumDate: lastDate, maximumDate: lastDate,
@ -144,8 +153,7 @@ class DateField extends StatelessWidget {
); );
}, },
); );
} } else {
else {
DateTime _selectedDate = await showDatePicker( DateTime _selectedDate = await showDatePicker(
context: context, context: context,
initialDatePickerMode: initialDatePickerMode, initialDatePickerMode: initialDatePickerMode,
@ -153,14 +161,12 @@ class DateField extends StatelessWidget {
firstDate: firstDate ?? DateTime(1900), firstDate: firstDate ?? DateTime(1900),
lastDate: lastDate ?? DateTime(2100)); lastDate: lastDate ?? DateTime(2100));
if (_selectedDate != null) { if (_selectedDate != null) {
onDateSelected(_selectedDate); onDateSelected(_selectedDate);
} }
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String text; String text;
@ -188,7 +194,13 @@ class DateField extends StatelessWidget {
/// user does click on it ! /// user does click on it !
class _InputDropdown extends StatelessWidget { class _InputDropdown extends StatelessWidget {
const _InputDropdown( const _InputDropdown(
{Key key, this.label, this.text, this.decoration, this.textStyle, this.onPressed, this.errorText}) {Key key,
this.label,
this.text,
this.decoration,
this.textStyle,
this.onPressed,
this.errorText})
: 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')
@ -223,12 +235,12 @@ class _InputDropdown extends StatelessWidget {
borderRadius: inkwellBorderRadius, borderRadius: inkwellBorderRadius,
onTap: onPressed, onTap: onPressed,
child: InputDecorator( child: InputDecorator(
decoration: decoration ?? InputDecoration( decoration: decoration ??
InputDecoration(
labelText: label, labelText: label,
errorText: errorText, errorText: errorText,
border: UnderlineInputBorder(borderSide: BorderSide()), border: UnderlineInputBorder(borderSide: BorderSide()),
contentPadding: EdgeInsets.only(bottom: 2.0) contentPadding: EdgeInsets.only(bottom: 2.0)),
),
baseStyle: textStyle, baseStyle: textStyle,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,

View file

@ -1,6 +1,6 @@
name: date_field name: date_field
description: Contains DateField and DateFormField description: Contains DateField and DateFormField which allows the user to pick a DateTime from an input field!
version: 0.0.1 version: 0.0.2
homepage: 'https://github.com/GaspardMerten/date_field' homepage: 'https://github.com/GaspardMerten/date_field'
environment: environment: