Issue
MyInputField(
title: "Tarih",
hint: DateFormat('dd/MM/yyyy').format(_selectedDate),
widget: IconButton(
onPressed: () {
_getDateFromUser();
},
Date data I show in TextFormField.
_getDateFromUser() async {
DateTime? _pickerDate = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2030));
if (_pickerDate != null) {
setState(() {
_pickerDate = _selectedDate;
});
}
}
}
The _getDateFromUser() function I defined
When I click on the icon to change the date, the calendar appears. But the date I changed doesn't change in TextFormField. DateFormat('dd/MM/yyyy') Is it because of this structure?
Solution
Turn the variables around. You want to assign the pickerDate to the selectedDate, not the other way around.
setState(() {
_pickerDate = _selectedDate;
});
to this:
setState(() {
_selectedDate = _pickerDate;
});
Answered By - Ozan Taskiran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.