showTimePickerPlus function

Future<TimeOfDay?> showTimePickerPlus({
  1. required BuildContext context,
  2. required TimeOfDay initialTime,
  3. TransitionBuilder? builder,
  4. bool useRootNavigator = true,
  5. TimePickerPlusEntryMode initialEntryMode = TimePickerPlusEntryMode.dial,
  6. String? cancelText,
  7. String? confirmText,
  8. String? helpText,
  9. RouteSettings? routeSettings,
})

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.

{@tool snippet} Show a dialog with initialTime equal to the current time.

Future<TimeOfDay?> selectedTime = showTimePicker(
  initialTime: TimeOfDay.now(),
  context: context,
);

{@end-tool}

The context, useRootNavigator and routeSettings arguments are passed to showDialog, the documentation for which discusses how it is used.

The builder parameter can be used to wrap the dialog widget to add inherited widgets like Localizations.override, Directionality, or MediaQuery.

The initialEntryMode parameter can be used to determine the initial time entry selection of the picker (either a clock dial or text input).

Optional strings for the helpText, cancelText, and confirmText can be provided to override the default values.

By default, the time picker gets its colors from the overall theme's ColorScheme. The time picker can be further customized by providing a TimePickerThemeData to the overall theme.

{@tool snippet} Show a dialog with the text direction overridden to be TextDirection.rtl.

Future<TimeOfDay?> selectedTimeRTL = showTimePicker(
  context: context,
  initialTime: TimeOfDay.now(),
  builder: (BuildContext context, Widget? child) {
    return Directionality(
      textDirection: TextDirection.rtl,
      child: child!,
    );
  },
);

{@end-tool}

{@tool snippet} Show a dialog with time unconditionally displayed in 24 hour format.

Future<TimeOfDay?> selectedTime24Hour = showTimePicker(
  context: context,
  initialTime: const TimeOfDay(hour: 10, minute: 47),
  builder: (BuildContext context, Widget? child) {
    return MediaQuery(
      data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
      child: child!,
    );
  },
);

{@end-tool}

See also:

  • showDatePicker, which shows a dialog that contains a material design date picker.
  • TimePickerThemeData, which allows you to customize the colors, typography, and shape of the time picker.

Implementation

Future<TimeOfDay?> showTimePickerPlus({
  required BuildContext context,
  required TimeOfDay initialTime,
  TransitionBuilder? builder,
  bool useRootNavigator = true,
  TimePickerPlusEntryMode initialEntryMode = TimePickerPlusEntryMode.dial,
  String? cancelText,
  String? confirmText,
  String? helpText,
  RouteSettings? routeSettings,
}) async {
  assert(context != null);
  assert(initialTime != null);
  assert(useRootNavigator != null);
  assert(initialEntryMode != null);
  assert(debugCheckHasMaterialLocalizations(context));

  final Widget dialog = _TimePickerDialog(
    initialTime: initialTime,
    initialEntryMode: initialEntryMode,
    cancelText: cancelText,
    confirmText: confirmText,
    helpText: helpText,
  );
  return showDialog<TimeOfDay>(
    context: context,
    useRootNavigator: useRootNavigator,
    builder: (BuildContext context) {
      return builder == null ? dialog : builder(context, dialog);
    },
    routeSettings: routeSettings,
  );
}