Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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;
}
},
),
]);
}
}
```