date/time picker formfields
two flutter widgets that wrap a textformfield and integrates the date and/or time picker dialogs.
widget | description |
---|---|
datetimepickerformfield |
for using the date picker and optionally the time picker too. yields datetime values. |
timepickerformfield |
for using the time picker only. yields timeofday values. |
example
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:datetime_picker_formfield/time_picker_formfield.dart';
const appname = 'datetimepickerformfield example';
void main() => runapp(materialapp(
title: appname,
home: myhomepage(),
theme: themedata.light().copywith(
inputdecorationtheme:
inputdecorationtheme(border: outlineinputborder())),
));
class myhomepage extends statefulwidget {
@override
myhomepagestate createstate() => myhomepagestate();
}
class myhomepagestate extends state<myhomepage> {
final dateformat = dateformat("eeee, mmmm d, yyyy 'at' h:mma");
final timeformat = dateformat("h:mm a");
datetime date;
timeofday time;
@override
widget build(buildcontext context) => scaffold(
appbar: appbar(title: text(appname)),
body: padding(
padding: edgeinsets.all(16.0),
child: listview(
children: <widget>[
datetimepickerformfield(
format: dateformat,
decoration: inputdecoration(labeltext: 'date'),
onchanged: (dt) => setstate(() => date = dt),
),
sizedbox(height: 16.0),
timepickerformfield(
format: timeformat,
decoration: inputdecoration(labeltext: 'time'),
onchanged: (t) => setstate(() => time = t),
),
sizedbox(height: 16.0),
text('date.tostring(): $date', style: textstyle(fontsize: 18.0)),
sizedbox(height: 16.0),
text('time.tostring(): $time', style: textstyle(fontsize: 18.0)),
],
),
));
}
Comments are closed.