Merge pull request #26 from axrs/master
This commit is contained in:
commit
97f41d6ab3
8 changed files with 100 additions and 274 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -29,6 +29,8 @@
|
||||||
.pub-cache/
|
.pub-cache/
|
||||||
.pub/
|
.pub/
|
||||||
build/
|
build/
|
||||||
|
pubspec.lock
|
||||||
|
**/pubspec.lock
|
||||||
|
|
||||||
# Android related
|
# Android related
|
||||||
**/android/**/gradle-wrapper.jar
|
**/android/**/gradle-wrapper.jar
|
||||||
|
|
|
@ -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
|
##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
|
* [TheGlorySaint](https://github.com/TheGlorySaint) added the possibility to use the 24Hour Format at the Timepicker. Default it is set to false
|
||||||
|
|
|
@ -15,7 +15,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
|
||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
dependencies:
|
||||||
...
|
...
|
||||||
date_field: ^2.1.2
|
date_field: ^3.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
In your library add the following import:
|
In your library add the following import:
|
||||||
|
|
|
@ -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"
|
|
|
@ -5,13 +5,33 @@ import 'package:intl/intl.dart';
|
||||||
final DateTime _kDefaultFirstSelectableDate = DateTime(1900);
|
final DateTime _kDefaultFirstSelectableDate = DateTime(1900);
|
||||||
final DateTime _kDefaultLastSelectableDate = DateTime(2100);
|
final DateTime _kDefaultLastSelectableDate = DateTime(2100);
|
||||||
|
|
||||||
const double _kCupertinoDatePickerHeight = 216;
|
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<DateTime>? 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]
|
/// [DateTimeField]
|
||||||
///
|
///
|
||||||
/// Shows an [_InputDropdown] that'll trigger [DateTimeField._selectDate] whenever the user
|
/// 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, ...)
|
/// clicks on it ! The date picker is **platform responsive** (ios date picker style for ios, ...)
|
||||||
class DateTimeField extends StatelessWidget {
|
class DateTimeField extends StatelessWidget {
|
||||||
|
// Note: This should match the definition of the [DateTimeFieldCreator]
|
||||||
DateTimeField({
|
DateTimeField({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.onDateSelected,
|
required this.onDateSelected,
|
||||||
|
@ -106,22 +126,11 @@ class DateTimeField extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Theme.of(context).platform == TargetPlatform.iOS) {
|
if (Theme.of(context).platform == TargetPlatform.iOS) {
|
||||||
showModalBottomSheet<void>(
|
final DateTime? _selectedDateTime =
|
||||||
context: context,
|
await showCupertinoPicker(context, initialDateTime);
|
||||||
builder: (BuildContext builder) {
|
if (_selectedDateTime != null) {
|
||||||
return SizedBox(
|
onDateSelected!(_selectedDateTime);
|
||||||
height: _kCupertinoDatePickerHeight,
|
}
|
||||||
child: CupertinoDatePicker(
|
|
||||||
mode: _cupertinoModeFromPickerMode(mode),
|
|
||||||
onDateTimeChanged: onDateSelected!,
|
|
||||||
initialDateTime: initialDateTime,
|
|
||||||
minimumDate: firstDate,
|
|
||||||
maximumDate: lastDate,
|
|
||||||
use24hFormat: use24hFormat,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
DateTime _selectedDateTime = initialDateTime;
|
DateTime _selectedDateTime = initialDateTime;
|
||||||
|
|
||||||
|
@ -132,14 +141,8 @@ class DateTimeField extends StatelessWidget {
|
||||||
];
|
];
|
||||||
|
|
||||||
if (modesWithDate.contains(mode)) {
|
if (modesWithDate.contains(mode)) {
|
||||||
final DateTime? _selectedDate = await showDatePicker(
|
final DateTime? _selectedDate =
|
||||||
context: context,
|
await showMaterialDatePicker(context, initialDateTime);
|
||||||
initialDatePickerMode: initialDatePickerMode!,
|
|
||||||
initialDate: initialDateTime,
|
|
||||||
initialEntryMode: initialEntryMode,
|
|
||||||
firstDate: firstDate,
|
|
||||||
lastDate: lastDate,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (_selectedDate != null) {
|
if (_selectedDate != null) {
|
||||||
_selectedDateTime = _selectedDate;
|
_selectedDateTime = _selectedDate;
|
||||||
|
@ -155,10 +158,8 @@ class DateTimeField extends StatelessWidget {
|
||||||
];
|
];
|
||||||
|
|
||||||
if (modesWithTime.contains(mode)) {
|
if (modesWithTime.contains(mode)) {
|
||||||
final TimeOfDay? _selectedTime = await showTimePicker(
|
final TimeOfDay? _selectedTime =
|
||||||
initialTime: TimeOfDay.fromDateTime(initialDateTime),
|
await showMaterialTimePicker(context, initialDateTime);
|
||||||
context: context,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (_selectedTime != null) {
|
if (_selectedTime != null) {
|
||||||
_selectedDateTime = DateTime(
|
_selectedDateTime = DateTime(
|
||||||
|
@ -175,6 +176,60 @@ 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<TimeOfDay?> 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<DateTime?> showMaterialDatePicker(
|
||||||
|
BuildContext context,
|
||||||
|
DateTime initialDateTime,
|
||||||
|
) {
|
||||||
|
return showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDatePickerMode: initialDatePickerMode!,
|
||||||
|
initialDate: initialDateTime,
|
||||||
|
initialEntryMode: initialEntryMode,
|
||||||
|
firstDate: firstDate,
|
||||||
|
lastDate: lastDate,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Launches the [CupertinoDatePicker] within a [showModalBottomSheet].
|
||||||
|
/// Can be @[override]n to allow further customization of the picker options
|
||||||
|
Future<DateTime?> showCupertinoPicker(
|
||||||
|
BuildContext context,
|
||||||
|
DateTime initialDateTime,
|
||||||
|
) async {
|
||||||
|
DateTime? pickedDate;
|
||||||
|
await showModalBottomSheet<DateTime?>(
|
||||||
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String? text;
|
String? text;
|
||||||
|
@ -203,7 +258,7 @@ enum DateTimeFieldPickerMode { time, date, dateAndTime }
|
||||||
/// Returns the [CupertinoDatePickerMode] corresponding to the selected
|
/// Returns the [CupertinoDatePickerMode] corresponding to the selected
|
||||||
/// [DateTimeFieldPickerMode]. This exists to prevent redundancy in the [DateTimeField]
|
/// [DateTimeFieldPickerMode]. This exists to prevent redundancy in the [DateTimeField]
|
||||||
/// widget parameters.
|
/// widget parameters.
|
||||||
CupertinoDatePickerMode _cupertinoModeFromPickerMode(
|
CupertinoDatePickerMode cupertinoModeFromPickerMode(
|
||||||
DateTimeFieldPickerMode mode) {
|
DateTimeFieldPickerMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case DateTimeFieldPickerMode.time:
|
case DateTimeFieldPickerMode.time:
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:date_field/src/field.dart';
|
import 'package:date_field/src/field.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
@ -31,6 +30,7 @@ class DateTimeFormField extends FormField<DateTime> {
|
||||||
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
|
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
|
||||||
DatePickerMode initialDatePickerMode = DatePickerMode.day,
|
DatePickerMode initialDatePickerMode = DatePickerMode.day,
|
||||||
DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
|
DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
|
||||||
|
DateTimeFieldCreator fieldCreator = DateTimeField.new,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
initialValue: initialValue,
|
initialValue: initialValue,
|
||||||
|
@ -54,7 +54,7 @@ class DateTimeFormField extends FormField<DateTime> {
|
||||||
field.didChange(value);
|
field.didChange(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DateTimeField(
|
return fieldCreator(
|
||||||
firstDate: firstDate,
|
firstDate: firstDate,
|
||||||
initialDate: initialDate,
|
initialDate: initialDate,
|
||||||
lastDate: lastDate,
|
lastDate: lastDate,
|
||||||
|
|
71
pubspec.lock
71
pubspec.lock
|
@ -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"
|
|
|
@ -1,10 +1,10 @@
|
||||||
name: date_field
|
name: date_field
|
||||||
description: A widget in the form of a field that lets people choose a date, a time or both.
|
description: A widget in the form of a field that lets people choose a date, a time or both.
|
||||||
version: 2.1.3
|
version: 3.0.0
|
||||||
homepage: 'https://github.com/GaspardMerten/date_field'
|
homepage: 'https://github.com/axrs/date_field'
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.15.0 <3.0.0'
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
Loading…
Reference in a new issue