Skip to content

Commit

Permalink
🐛 fix remove event properly from controller. (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthBaraiya authored Mar 2, 2022
1 parent 61f3f84 commit 85a2152
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions lib/src/event_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ class EventController<T> extends ChangeNotifier {
void remove(CalendarEventData<T> event) {
for (final e in _events) {
if (e.year == event.date.year) {
e.removeEvent(event);
_eventList.remove(event);
notifyListeners();
return;
if (e.removeEvent(event) && _eventList.remove(event)) {
notifyListeners();
return;
}

break;
}
}

for (final e in _rangingEventList) {
if (e == event) {
_rangingEventList.remove(event);
_eventList.remove(event);
notifyListeners();
return;
if (_rangingEventList.remove(event) && _eventList.remove(event)) {
notifyListeners();
return;
}
break;
}
}
}
Expand Down Expand Up @@ -184,12 +187,13 @@ class _YearEvent<T> {
return totalEvents;
}

void removeEvent(CalendarEventData<T> event) {
bool removeEvent(CalendarEventData<T> event) {
for (final e in _months) {
if (e.month == event.date.month) {
e.removeEvent(event);
return e.removeEvent(event);
}
}
return false;
}
}

Expand All @@ -216,7 +220,13 @@ class _MonthEvent<T> {
return false;
}

void removeEvent(CalendarEventData<T> event) {
_events.removeWhere((e) => e == event);
bool removeEvent(CalendarEventData<T> event) {
final index = _events.indexWhere((element) => element == event);
if (index == -1) {
return false;
} else {
_events.removeAt(index);
return true;
}
}
}

0 comments on commit 85a2152

Please sign in to comment.