diff --git a/lib/src/event_controller.dart b/lib/src/event_controller.dart index eeb97a03..4a395a51 100644 --- a/lib/src/event_controller.dart +++ b/lib/src/event_controller.dart @@ -159,7 +159,9 @@ class EventController extends ChangeNotifier { 'The end date must be greater or equal to the start date'); if (_calendarData.eventList.contains(event)) return; if (event.endDate.difference(event.date).inDays > 0) { - if (event.startTime!.isDayStart && event.endTime!.isDayStart) { + if (event.startTime == null || + event.endTime == null || + (event.startTime!.isDayStart && event.endTime!.isDayStart)) { _calendarData.fullDayEventList.addEventInSortedManner(event); } else { _calendarData.rangingEventList.addEventInSortedManner(event); diff --git a/lib/src/extensions.dart b/lib/src/extensions.dart index c852bbbe..a246119f 100644 --- a/lib/src/extensions.dart +++ b/lib/src/extensions.dart @@ -170,17 +170,20 @@ extension MyList on List { // 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) { + if ((event.startTime?.getTotalMinutes ?? 0) - + (this[i].startTime?.getTotalMinutes ?? 0) <= + 0) { addIndex = i; break; } } if (addIndex > -1) { - this.insert(addIndex, event); + insert(addIndex, event); } else { - this.add(event); + add(event); } } }