suppose you have a API and a key-value for this API is
"time": "22:05"
i want to show this time in a in a field and when i press the field the date time picker is pop up with time value and i change the time like 22:40 and the 22:05 will replace to 22:40
I have try this..
time = TimeOfDay.now();
final String hour = time.hour.toString().padLeft(2, '0');
final String minute = time.minute.toString().padLeft(2, '0');
GestureDetector(
onTap: () async {
TimeOfDay? pickTime = await showTimePicker(
context: context,
initialTime: time,
);
if (pickTime != null) {
setState(() => time = pickTime);
}
It always show my current system time
2
Answers
Here is a working example:
this is my usual way. with
TextFormfied
. so you can use validator if you need too.result:
demo : https://dartpad.dev/?id=be4ccb0cad0930c9797bb4c2b63cd70e