getTimesShortName method Null safety

String getTimesShortName(
  1. List<TimeCode>? timeCode
)

Implementation

String getTimesShortName(List<TimeCode>? timeCode) {
  String text = '';
  if ((times?.length ?? 0) == 0) return text;
  int startIndex = -1;
  int repeat = 0;
  final len = times?.length ?? 0;
  for (var i = 0; i < len; i++) {
    final time = times![i];
    if (startIndex != -1 &&
        time.index! - 1 == times![i - 1].index &&
        time.weekday == times![i - 1].weekday) {
      repeat++;
      if (i == len - 1 ||
          times![i + 1].weekday != times![i].weekday ||
          times![i + 1].index != times![i].index! + 1) {
        final endTime = times![startIndex + repeat];
        text += '-'
            '${timeCode![endTime.index!].title}';
        repeat = 0;
        startIndex = -1;
      }
    } else {
      startIndex = i;
      text += '${text.isEmpty ? '' : ' '}'
          '(${ApLocalizations.current.weekdaysCourse[time.weekDayIndex]}) '
          '${timeCode![time.index!].title}';
    }
  }
  return text;
}