joinDateWithTime function Null safety

DateTime joinDateWithTime(
  1. {required DateTime date,
  2. TimeOfDay? time}
)

Implementation

DateTime joinDateWithTime({required DateTime date, TimeOfDay? time}) {
  String d = date.toString().substring(0, 11);

  if (time != null) {
    DateTime newDate = DateTime.parse(d +
        correctFormatTime(time.hour) +
        correctFormatTime(time.minute) +
        ":00.000000");

    return newDate;
  } else {
    DateTime newDate = DateTime.parse(
        d + correctFormatTime(0) + correctFormatTime(0) + ":00.000000");

    return newDate;
  }
}