showPicker method Null safety

void showPicker(
  1. BuildContext context
)

Implementation

void showPicker(BuildContext context) {
  if (initialStartTime == null) {
    initialStartTime = DateTime.now();
  }

  // Remove minutes and seconds to prevent exception of cupertino picker: initial minute is not divisible by minute interval
  initialStartTime = initialStartTime!.subtract(Duration(
      minutes: initialStartTime!.minute, seconds: initialStartTime!.second));

  if (initialEndTime == null) {
    initialEndTime = initialStartTime!.add(Duration(
        days: mode == DateTimeRangePickerMode.time ? 0 : 1,
        hours: mode == DateTimeRangePickerMode.time ? 2 : 0));
  }

  initialEndTime = initialEndTime!.subtract(Duration(
      minutes: initialEndTime!.minute, seconds: initialEndTime!.second));

  if (minimumTime != null) {
    minimumTime = minimumTime!.subtract(
        Duration(minutes: minimumTime!.minute, seconds: minimumTime!.second));
  }

  if (maximumTime != null) {
    maximumTime = maximumTime!.subtract(
        Duration(minutes: maximumTime!.minute, seconds: maximumTime!.second));
  }

  var pickerMode = CupertinoDatePickerMode.dateAndTime;

  switch (mode) {
    case DateTimeRangePickerMode.date:
      {
        pickerMode = CupertinoDatePickerMode.date;
      }
      break;

    case DateTimeRangePickerMode.time:
      {
        pickerMode = CupertinoDatePickerMode.time;
      }
      break;

    default:
      {
        pickerMode = CupertinoDatePickerMode.dateAndTime;
      }
      break;
  }

  showDialog(
      context: context,
      builder: (BuildContext context) {
        return FractionallySizedBox(
          widthFactor: 0.8,
          heightFactor: 0.5,
          child: PickerWidget([
            Tab(text: startText),
            Tab(text: endText),
          ],
              initialStartTime!,
              initialEndTime!,
              interval,
              this.onCancel,
              this.onConfirm,
              pickerMode,
              this.doneText,
              this.cancelText,
              this.minimumTime!,
              this.maximumTime!,
              this.use24hFormat),
        );
      });
}