defaultRemoveListener method

  1. @protected
void defaultRemoveListener(
  1. ChangeListener listener
)

Remove a listener from the list of listeners.

  • listener The listener to remove.

Implementation

@protected
void defaultRemoveListener(ChangeListener listener) {
  // This method is allowed to be called on disposed instances for usability
  // reasons. Due to how our frame scheduling logic between render objects and
  // overlays, it is common that the owner of this instance would be disposed a
  // frame earlier than the listeners. Allowing calls to this method after it
  // is disposed makes it easier for listeners to properly clean up.
  for (int i = 0; i < _count; i++) {
    final ChangeListener? listenerAtIndex = _listeners[i];
    if (listenerAtIndex == listener) {
      if (_notificationCallStackDepth > 0) {
        // We don't resize the list during notifyListeners iterations
        // but we set to null, the listeners we want to remove. We will
        // effectively resize the list at the end of all notifyListeners
        // iterations.
        _listeners[i] = null;
        _reentrantlyRemovedListeners++;
      } else {
        // When we are outside the notifyListeners iterations we can
        // effectively shrink the list.
        _removeAt(i);
      }
      break;
    }
  }
}