showTimePicker function

Future<TimeOfDay> showTimePicker ({@required BuildContext context, @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.

To show a dialog with initialTime equal to the current time:

showTimePicker(
  initialTime: TimeOfDay.now(),
  context: context,
);

The context argument is passed to showDialog, the documentation for which discusses how it is used.

See also:

Implementation

Future<TimeOfDay> showTimePicker({
  @required BuildContext context,
  @required TimeOfDay initialTime
}) async {
  assert(context != null);
  assert(initialTime != null);
  assert(debugCheckHasMaterialLocalizations(context));

  return await showDialog<TimeOfDay>(
    context: context,
    builder: (BuildContext context) => _TimePickerDialog(initialTime: initialTime),
  );
}