cancelListener method

void cancelListener(
  1. VoidCallback? listener
)

Cancels a single listener, if present.

Implementation

void cancelListener(VoidCallback? listener) {
  if (listener == null) return;

  assert(_listenables.length == _listeners.length);
  final foundIndex =
      _listeners.indexWhere((currentListener) => currentListener == listener);
  if (foundIndex == -1) return;
  _listenables[foundIndex].removeListener(_listeners[foundIndex]);
  _listenables.removeAt(foundIndex);
  _listeners.removeAt(foundIndex);
}