Reputation: 1
The current date is already written in the text button. When you press it, a CupertinoDatePicker pops up, but I want to change the written date instantly when I change the date in CupertinoDatePicker. With normal date picker it is possible but after a few hours of work I couldn't figure out how to do that with CupertinoDatePicker.
Upvotes: 0
Views: 222
Reputation: 1671
In CupertinoDatePicker widget we have onDateTimeChanged method. you can update the string inside it. Here's an example
String fromDate = "";
@override
void initState() {
fromDate = DateTime.now().toString();
super.initState();
}
TextButton(onPressed: () {
showModalBottomSheet(context: context, builder: (context) {
return Column(
children: [
ListTile(
leading: Text('Cancel'),
trailing: Text('Done'),
),
Expanded(
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (value) {
debugPrint('value: $value');
//Update your string here
setState(() {
fromDate = value.toString();
});
},),
)
],
);
},);
}, child: Text(fromDate))
Upvotes: 0