Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Removes force unwrap while sorting the events. #295

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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);
}
}
}
Expand Down
Loading