removeListener method

void removeListener(
  1. ObjectEventListener listener
)

Stop calling the given listener every time an object event is dispatched.

Listeners can be added with addListener.

Only call this when kFlutterMemoryAllocationsEnabled is true.

Implementation

void removeListener(ObjectEventListener listener){
  if (!kFlutterMemoryAllocationsEnabled) {
    return;
  }
  final List<ObjectEventListener?>? listeners = _listeners;
  if (listeners == null) {
    return;
  }

  if (_activeDispatchLoops > 0) {
    // If there are active dispatch loops, listeners.remove
    // should not be invoked, as it will
    // break the dispatch loops correctness.
    for (int i = 0; i < listeners.length; i++) {
      if (listeners[i] == listener) {
        listeners[i] = null;
        _listenersContainNulls = true;
      }
    }
  } else {
    listeners.removeWhere((ObjectEventListener? l) => l == listener);
    _checkListenersForEmptiness();
  }
}