dispose method

  1. @override
void dispose()
override

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

@override
void dispose() {
  super.dispose();

  /// The controller isn't recreated on provider rebuild. So we only close it
  /// when the element is destroyed, not on "ref.onDispose".
  _streamController.close();
}