startTimeEnumToTimeOfDay function

DateTime? startTimeEnumToTimeOfDay(
  1. String startTimeEnum,
  2. DateTime? startTime
)

converts a startTimeEnum value and startTime to a DateTime object representing the adjusted time of day, returning the adjusted DateTime value or null

Implementation

DateTime? startTimeEnumToTimeOfDay(String startTimeEnum, DateTime? startTime) {
  // ignore: unnecessary_null_comparison
  if (startTimeEnum == null ||
      startTimeEnum.trim().isEmpty ||
      startTime == null) {
    return startTime;
  }
  switch (startTimeEnum.toString()) {
    case 'LOC_START_TIME_ENUM.TWO_HOURS':
      return startTime.subtract(const Duration(hours: 2));

    case 'LOC_START_TIME_ENUM.SIXTY_MIN':
      return startTime.subtract(const Duration(minutes: 60));

    case 'LOC_START_TIME_ENUM.THIRTY_MIN':
      return startTime.subtract(const Duration(minutes: 30));
  }
  return null;
}