timePicker static method

dynamic timePicker({
  1. required BuildContext context,
  2. required dynamic onSelected(
    1. String time
    ),
  3. String? time,
  4. String? minTime,
  5. String? maxTime,
  6. bool format24Hours = false,
  7. bool hasSeconds = false,
  8. TimePickerEntryMode timePickerEntryMode = TimePickerEntryMode.dial,
})

pick time with customization time HH:mm:ss

Implementation

static timePicker(
    {required BuildContext context,
    required Function(String time) onSelected,
    String? time,
    String? minTime,
    String? maxTime,
    bool format24Hours = false,
    bool hasSeconds = false,
    TimePickerEntryMode timePickerEntryMode = TimePickerEntryMode.dial}) {
  showTimePicker(
          context: context,
          initialTime: stringToTimeOfDay(time: time),
          initialEntryMode: timePickerEntryMode,
          builder: format24Hours
              ? (context, child) {
                  return MediaQuery(
                    data: MediaQuery.of(context).copyWith(
                      alwaysUse24HourFormat: true,
                    ),
                    child: child ?? Container(),
                  );
                }
              : null)
      .then((value) {
    String selectedTime = "";
    if (value != null) {
      selectedTime = timeOfDayToString(time: value, hasSeconds: hasSeconds);
    } else {
      selectedTime = _isNullOrEmpty(time)
          ? ""
          : hasSeconds
              ? time!
              : timeOfDayToString(
                  time: stringToTimeOfDay(time: time),
                  hasSeconds: hasSeconds);
    }
    onSelected(selectedTime);
  });
}