Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jifalops/datetime_picker_formfield
A Flutter widget that wraps a TextFormField and integrates the date and/or time picker dialogs.
https://github.com/jifalops/datetime_picker_formfield
Last synced: 4 days ago
JSON representation
A Flutter widget that wraps a TextFormField and integrates the date and/or time picker dialogs.
- Host: GitHub
- URL: https://github.com/jifalops/datetime_picker_formfield
- Owner: jifalops
- License: mit
- Created: 2018-06-13T20:59:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-06T10:34:33.000Z (over 2 years ago)
- Last Synced: 2024-12-29T18:12:11.267Z (11 days ago)
- Language: Dart
- Size: 924 KB
- Stars: 186
- Watchers: 11
- Forks: 101
- Open Issues: 46
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# DateTimeField
A TextFormField that emits DateTimes and helps show Material, Cupertino, and other style picker dialogs.
## Example
See the example tab (example/lib/main.dart) for more.
![screenshot.gif](screenshot.gif)
```dart
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';// ...
class BasicDateField extends StatelessWidget {
final format = DateFormat("yyyy-MM-dd");
@override
Widget build(BuildContext context) {
return Column(children: [
Text('Basic date field (${format.pattern})'),
DateTimeField(
format: format,
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime(1900),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100));
},
),
]);
}
}class BasicTimeField extends StatelessWidget {
final format = DateFormat("HH:mm");
@override
Widget build(BuildContext context) {
return Column(children: [
Text('Basic time field (${format.pattern})'),
DateTimeField(
format: format,
onShowPicker: (context, currentValue) async {
final time = await showTimePicker(
context: context,
initialTime: TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
);
return DateTimeField.convert(time);
},
),
]);
}
}class BasicDateTimeField extends StatelessWidget {
final format = DateFormat("yyyy-MM-dd HH:mm");
@override
Widget build(BuildContext context) {
return Column(children: [
Text('Basic date & time field (${format.pattern})'),
DateTimeField(
format: format,
onShowPicker: (context, currentValue) async {
final date = await showDatePicker(
context: context,
firstDate: DateTime(1900),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100));
if (date != null) {
final time = await showTimePicker(
context: context,
initialTime:
TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
);
return DateTimeField.combine(date, time);
} else {
return currentValue;
}
},
),
]);
}
}
```