diff --git a/lib/src/event_controller.dart b/lib/src/event_controller.dart index 162dfff6..2a849ea4 100644 --- a/lib/src/event_controller.dart +++ b/lib/src/event_controller.dart @@ -58,19 +58,22 @@ class EventController extends ChangeNotifier { void remove(CalendarEventData 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; } } } @@ -184,12 +187,13 @@ class _YearEvent { return totalEvents; } - void removeEvent(CalendarEventData event) { + bool removeEvent(CalendarEventData event) { for (final e in _months) { if (e.month == event.date.month) { - e.removeEvent(event); + return e.removeEvent(event); } } + return false; } } @@ -216,7 +220,13 @@ class _MonthEvent { return false; } - void removeEvent(CalendarEventData event) { - _events.removeWhere((e) => e == event); + bool removeEvent(CalendarEventData event) { + final index = _events.indexWhere((element) => element == event); + if (index == -1) { + return false; + } else { + _events.removeAt(index); + return true; + } } }