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 1dfd2b4
Showing 1 changed file with 6 additions and 3 deletions.
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 1dfd2b4

Please sign in to comment.