Skip to main content

customTimePicker function

Future<TimeOfDay> customTimePicker ({required TimeOfDay initialTime})

Shows a dialog containing a material design time picker.

The returned Future resolves to the time selected by the user when the user closes the dialog. If the user cancels the dialog, null is returned.

Implementation

Future<TimeOfDay> customTimePicker({required TimeOfDay initialTime}) async {
// showTimePicker which shows a material design time range picker used to select a range of times.
// Click ![here](https://api.flutter.dev/flutter/material/showTimePicker.html) to know more.
final TimeOfDay? pickedTime = await showTimePicker(
context: navigationService.navigatorKey.currentContext!,
initialTime: initialTime,
);

if (pickedTime != null && pickedTime != initialTime) {
return pickedTime;
}
return initialTime;
}