1.This is first code :
DateTime? _selectedTime;
void _datePicker(BuildContext con2) {
showDatePicker(
initialDate: DateTime.utc(2021, 12, 21),
firstDate: DateTime(2000),
lastDate: DateTime.now(),
context: con2,
// ignore: non_constant_identifier_names
).then((UserSelect) {
if (UserSelect == null) {
return;
}
setState(() {
UserSelect = _selectedTime;
});
});
}
2.this is second :
body: Container(
color: Colors.black,
height: double.infinity,
child: Center(
child: ElevatedButton(
onPressed: () {
_datePicker(context);
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.purple)),
child: Text(
'${DateFormat('yyyy/MM/dd').format(_selectedTime!)}',