timeSelect static method

Future<TimeOfDay?> timeSelect(
  1. BuildContext context, {
  2. TimeOfDay? initialTime,
  3. TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial,
  4. String helpText = "Select time",
  5. String cancelText = "Cancel",
  6. String confirmText = "Confirm",
  7. bool is24HourFormat = false,
  8. TimeSelectListener? selectListener,
})

Implementation

static Future<TimeOfDay?> timeSelect(
    BuildContext context, {
      TimeOfDay? initialTime,
      TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial,
      String helpText = "Select time",
      String cancelText = "Cancel",
      String confirmText = "Confirm",
      bool is24HourFormat = false,
      TimeSelectListener? selectListener}) async{

  late Future<TimeOfDay?> timeSelected;
  final now = DateTime.now();
  if(Platform.isIOS){
    final datePicker = CupertinoDatePicker(
      onDateTimeChanged: (date) async{
        if(selectListener != null){
          selectListener(TimeOfDay.fromDateTime(date));
        }
        timeSelected = NUIAsync.delayForResult(Duration(milliseconds: 100), () async{
          final timeOfDay = TimeOfDay.fromDateTime(date);
          return timeOfDay;
        });
      },
      initialDateTime: DateTime(now.year, now.month, now.day, initialTime?.hour ?? now.hour, initialTime?.minute ?? now.minute, now.second),
      mode: CupertinoDatePickerMode.time,
    );
    showNUIBottomSheet(context: context, content: (context){
      return Container(
        height: screenHeight(context)/3,
        color: NUIColors.NUIWhite,
        child: datePicker,
      );
    });
  }
  else {
    timeSelected = showTimePicker(
        context: context,
        initialTime: initialTime ?? TimeOfDay.now(),
        initialEntryMode: initialEntryMode,
        helpText: helpText,
        cancelText: cancelText,
        confirmText: confirmText,
        builder: (context, child) => MediaQuery(data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: is24HourFormat), child: child!),

    );
  }

  final timeResult = await timeSelected;
  if (selectListener != null) {
    selectListener(timeResult);
  }
  return timeResult;
}