I have this code of time picker, then I want to set the initial Time from a DateTime variable:
Future<Null> _selectTime(BuildContext context) async {
final TimeOfDay pickedS = await showTimePicker(
context: context,
initialTime: createdAt,
builder: (BuildContext context, Widget child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
child: child,
);});
if (pickedS != null && pickedS != selectedTime )
setState(() {
selectedTime = pickedS;
myTweets[actualTweetIndex].createdAt = dateFormat.format(selectedDate.toLocal()) +' ${selectedTime.hour}:${selectedTime.minute}:00 +0000 '+ selectedDate.year.toString();
});
}
The TimeOfDay class has a dedicated constructor for that:
TimeOfDay.fromDateTime(DateTime time)
You can check the documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With