dispose method

  1. @override
void dispose({
  1. bool evictImageFromCache = false,
})
override

Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).

This method should only be called by the object's owner.

This method does not notify listeners, and clears the listener list once it is called. Consumers of this class must decide on whether to notify listeners or not immediately before disposal.

Implementation

@override
void dispose({bool evictImageFromCache = false}) {
  assert(!_disposed);
  _disposed = true;

  if (evictImageFromCache) {
    try {
      imageProvider.evict().catchError((Object e) {
        debugPrint(e.toString());
        return false;
      });
    } catch (e) {
      // This may be never called because catchError will handle errors, however
      // we want to avoid random crashes like in #444 / #536
      debugPrint(e.toString());
    }
  }

  // Mark the image as inactive.
  _active = false;
  _animationController?.stop(canceled: false);
  _animationController?.value = 0.0;
  notifyListeners();

  _animationController?.dispose();
  _imageStream?.removeListener(_listener);
  super.dispose();
}