From 539cbbeec73ea03eb1f4f5bd1845babbb5346970 Mon Sep 17 00:00:00 2001 From: Parth Baraiya Date: Thu, 23 Nov 2023 18:26:24 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Removes=20force=20unwrap=20while=20?= =?UTF-8?q?sorting=20the=20events.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixes issue #282 --- CHANGELOG.md | 1 + lib/src/event_controller.dart | 4 +++- lib/src/extensions.dart | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d5943e..1f8b348d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,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) +- 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 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); } } }