Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null check exception when adding multiple events without startTime #282

Closed
philitell opened this issue Nov 7, 2023 · 0 comments · Fixed by #295
Closed

Null check exception when adding multiple events without startTime #282

philitell opened this issue Nov 7, 2023 · 0 comments · Fixed by #295
Labels
bug Something isn't working in progress This label defines issues that are in progress. priority:1 Bug/Enhancement with highest priority.

Comments

@philitell
Copy link

When adding multiple events without startTime to a day - a null check exception occurs.

    for (CalendarGarbageEntry calendarGarbageEntry in selectedCalendarGarbageEntries) {
      final event = CalendarEventData<CalendarGarbageEntry>(
          date: date,
          color: Color(calendarGarbageEntry.garbageCategory.color),
          title: calendarGarbageEntry.garbageCategory.name,
          event: calendarGarbageEntry);
      newEvents.add(event);
    }

Reason for that is a bug: Sorting algorithm expects startTime even though it is optional.

// CalendarEvent:
CalendarEventData<CalendarGarbageEntry> CalendarEventData
({   
  required String title,   
  String description = "",   
  CalendarGarbageEntry? event,   
  Color color = Colors.blue,   
  DateTime? startTime,     // <----- startTime is optional/nullable
  DateTime? endTime,   
  TextStyle? titleStyle,   
  TextStyle? descriptionStyle,   
  DateTime? endDate,   
  required DateTime date, 
})



// extensions.dart
extension MyList on List<CalendarEventData> {
  // Below function will add the new event in sorted manner(startTimeWise) in
  // the existing list of CalendarEventData.
  void addEventInSortedManner(CalendarEventData event) {
    var addIndex = -1;
    for (var i = 0; i < this.length; i++) {
      if (event.startTime!.compareTo(this[i].startTime!) <= 0) {      //<---- startTime is required here
        addIndex = i;
        break;
      }
    }

    if (addIndex > -1) {
      this.insert(addIndex, event);
    } else {
      this.add(event);
    }
  }
}

Please change implementation in addEventInSortedManner or make startTime required/non-nullable

@PRBaraiya PRBaraiya added bug Something isn't working priority:1 Bug/Enhancement with highest priority. in progress This label defines issues that are in progress. labels Nov 22, 2023
PRBaraiya added a commit that referenced this issue Nov 23, 2023
@PRBaraiya PRBaraiya linked a pull request Nov 23, 2023 that will close this issue
7 tasks
PRBaraiya added a commit that referenced this issue Nov 23, 2023
PRBaraiya added a commit that referenced this issue Nov 24, 2023
PRBaraiya added a commit that referenced this issue Dec 13, 2023
ParthBaraiya pushed a commit that referenced this issue Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress This label defines issues that are in progress. priority:1 Bug/Enhancement with highest priority.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants