pickTime static method

Future<TimeOfDay?> pickTime({
  1. required BuildContext context,
  2. TimeOfDay? initialTime,
  3. PickerStyle style = PickerStyle.platform,
  4. bool use24hFormat = true,
  5. String doneLabel = 'Done',
  6. String cancelLabel = 'Cancel',
  7. Color? backgroundColor,
  8. Color? accentColor,
})

Implementation

static Future<TimeOfDay?> pickTime({
  required BuildContext context,
  TimeOfDay? initialTime,
  PickerStyle style = PickerStyle.platform,
  bool use24hFormat = true,
  String doneLabel = 'Done',
  String cancelLabel = 'Cancel',
  Color? backgroundColor,
  Color? accentColor,
}) async {
  initialTime ??= TimeOfDay.now();
  final PickerStyle pickerStyle = _resolveStyle(context, style);

  if (pickerStyle == PickerStyle.ios) {
    final DateTime? picked = await _cupertinoPicker(
      context: context,
      initialDate: DateTime(0, 1, 1, initialTime.hour, initialTime.minute),
      mode: CupertinoDatePickerMode.time,
      use24hFormat: use24hFormat,
      doneLabel: doneLabel,
      cancelLabel: cancelLabel,
      backgroundColor: backgroundColor,
      accentColor: accentColor,
    );
    return picked != null
        ? TimeOfDay(hour: picked.hour, minute: picked.minute)
        : null;
  }

  return showTimePicker(
    context: context,
    initialTime: initialTime,
    builder: (BuildContext ctx, Widget? child) =>
        _applyAccent(ctx, child, accentColor),
  );
}