Skip to content

Commit

Permalink
✨ Removes force unwrap while sorting the events.
Browse files Browse the repository at this point in the history
- Fixes issue #282
  • Loading branch information
PRBaraiya committed Nov 23, 2023
1 parent 672b2cf commit 0186ab9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/src/event_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class EventController<T extends Object?> 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);
Expand Down
9 changes: 6 additions & 3 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,20 @@ extension MyList on List<CalendarEventData> {
// 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);
}
}
}

0 comments on commit 0186ab9

Please sign in to comment.