removeListener method

  1. @override
void removeListener(
  1. VoidCallback listener
)
override

Removes a previously-registered listener.

Implementation

@override
void removeListener(VoidCallback listener) {
  for (var i = 0; i < _count; i++) {
    if (_listeners[i] == listener) {
      if (_notificationDepth > 0) {
        // Null the slot instead of shrinking so the in-progress index walk
        // stays valid; the not-yet-called listener is skipped, and the gap
        // is compacted away when the outermost notification returns.
        _listeners[i] = null;
        _reentrantlyRemoved += 1;
      } else {
        _removeAt(i);
      }
      return; // Remove only the first matching registration.
    }
  }
}