removeDependent method

  1. @override
void removeDependent(
  1. Element dependent
)
override

Called by Element.deactivate to remove the provided dependent Element from this InheritedElement.

After the dependent is removed, Element.didChangeDependencies will no longer be called on it when this InheritedElement notifies its dependents.

Subclasses can override this method to release any resources retained for a given dependent.

Implementation

@override
void removeDependent(Element dependent) {
  final ids = _serviceDependents.remove(dependent);

  if (ids is Set<ServiceId>) {
    for (final id in ids) {
      final subscription = _subscriptions[id];

      if (subscription != null) {
        subscription.watchers.remove(dependent);
        subscription.readers.remove(dependent);

        // Dispose of the service if it is no longer referenced by any widget.
        if (subscription.referenceCount == 0) {
          _subscriptions.remove(id)?.dispose();
        }
      }
    }
  }

  super.removeDependent(dependent);
}