diff --git a/CHANGELOG.md b/CHANGELOG.md index a1005d03..3742ad26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Added feature added Support for changing the week day position(top/bottom) in weekView. [#283](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/283) - Adds new flag `includeEdges` in `EventArrangers`. [#290](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/pull/294) +- Fixes null check exception while adding events. [#282](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/282) # [1.0.4 - 9 Aug 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.4) 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 6761e2bb..e97c842b 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); } } }