dispose method

  1. @protected
  2. @mustCallSuper
void dispose()

Release the resources associated to this ProviderElementBase.

This will be invoked when:

  • the provider is using autoDispose and it is no-longer used.
  • the associated ProviderContainer is disposed

On the other hand, this life-cycle will not be executed when a provider rebuilds.

As opposed to runOnDispose, this life-cycle is executed only for the lifetime of this element.

Implementation

@protected
@mustCallSuper
void dispose() {
  runOnDispose();

  for (final sub in _dependencies.entries) {
    sub.key._providerDependents.remove(this);
    sub.key._onRemoveListener();
  }
  _dependencies.clear();

  // TODO test invalidateSelf() then dispose() properly unlinks dependencies
  // TODO test [listen] calls are cleared
}