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 24, 2023
1 parent 672b2cf commit 539cbbe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
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 539cbbe

Please sign in to comment.