In my CupertinoDatePickerMode.time
, I need to slide the picker for setting the time which is currently on the picker with onDateTimeChanged
. I click the button and the picker pops up. I can set the time like I said only after sliding the picker.
So my question is: How can I set the time when just the picker pops up.
This is my variable:
DateTime? selectedDayStart;
This is my picker:
return CupertinoDatePicker(
mode: CupertinoDatePickerMode.time,
minuteInterval: 15,
initialDateTime: _initialTime,
use24hFormat: true,
onDateTimeChanged: (time) {
setState(() {
selectedDayStart = DateTime(
selectedDayStart!.year,
selectedDayStart!.month,
selectedDayStart!.day,
time.hour,
time.minute);
});
},
);
This is how I show the time:
Text(
"Başlangıç Saati ${DateFormat("HH:mm").format(selectedDayStart!)}",
style: const TextStyle(fontSize: 20),
)
2
Answers
I solved it with using CupertinoDatePicker in Stateful Widget and called initState
You can set Time on
initialDateTime
.