Professor, estou tentando colocar a data do showDatePicker no TextField e não estou conseguindo. Tem alguma dica?
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Home(),
));
}
class Home extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<Home> {
DateTime _dateTime;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Teste de Data", ),
),
body: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(20.0),
child: TextField(
keyboardType: TextInputType.datetime,
decoration: InputDecoration(
icon: IconButton(
icon: Icon(Icons.date_range, color: Colors.purple,),
onPressed: () async {
final _dateTime = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(1930),
lastDate: DateTime(2030)
);
setState(() {});
var dataformato;
Text (dataformato = DateFormat('dd/MM/yyyy').format(_dateTime));
print(dataformato);
},
),
),
),
),
],
),
);
}
}