-1
Good afternoon!
I’m starting my studies in Flutter
and I created a simple form, where when clicking on a date field, it displays the datepicker, but when selecting the date the field is not filled. The code is like this:
class _FormScreenState extends State<FormScreen> {
DateTime _date = DateTime.now();
Future<Null> _selectcDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: _date,
firstDate: DateTime(1990),
lastDate: DateTime(2030),
);
if (picked != null && picked != _date) {
setState(() {
_date = picked;
print(_date.toString());
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Formulário'),
),
drawer: AppDrawer(),
body: Padding(
padding: const EdgeInsets.all(15.0),
child: Form(
child: ListView(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(top: 20),
isDense: true,
hintText: "Data",
prefixIcon: Padding(
padding: EdgeInsets.only(top: 15),
child: Icon(Icons.alarm),
)
),
onTap: () {
_selectcDate(context);
},
),
],
),
),
),
);
}
}