evict method

Future<bool> evict ({ImageCache cache, ImageConfiguration configuration: ImageConfiguration.empty })

Evicts an entry from the image cache.

Returns a Future which indicates whether the value was successfully removed.

The ImageProvider used does not need to be the same instance that was passed to an Image widget, but it does need to create a key which is equal to one.

The cache is optional and defaults to the global image cache.

The configuration is optional and defaults to ImageConfiguration.empty.

The following sample code shows how an image loaded using the Image widget can be evicted using a NetworkImage with a matching url.
class MyWidget extends StatelessWidget {
  final String url = '...';

  @override
  Widget build(BuildContext context) {
    return Image.network(url);
  }

  void evictImage() {
    final NetworkImage provider = NetworkImage(url);
    provider.evict().then<void>((bool success) {
      if (success)
        debugPrint('removed image!');
    });
  }
}

Implementation

Future<bool> evict({ImageCache cache, ImageConfiguration configuration = ImageConfiguration.empty}) async {
  cache ??= imageCache;
  final T key = await obtainKey(configuration);
  return cache.evict(key);
}