Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear cache in CachedNetworkImage flutter

i dont want to store image in cache.. iam using CachedNetworkImage for image loading.. I want know is there any option to remove or do not store image in cache like picasso..

my code:

var annotatedImg = CachedNetworkImage(
      fit: BoxFit.fill,
      imageUrl: Constants.IMAGE_BASE_URL + widget._fileId + Constants.CONTOUR_IMG_SUFFIX,
      placeholder: (context, url) => progressBar,
      errorWidget: (context, url, error) => new Icon(Icons.error),
    );

i have tried

annotatedImg.cacheManager.emptyCache();

but its shows cant call emptyCache is null..

like image 231
Navin Kumar Avatar asked Jul 16 '19 14:07

Navin Kumar


People also ask

How do I clear app cache programmatically in Flutter?

Go to Tools > Flutter > Flutter Clean to clear the build cache of the Flutter project.

How do you refresh a network image in Flutter?

Another tricky solution is to add a dummy argument which changes every time, then the image will be treat as different image source and will refresh image every time when you access it. For example add t=currentTimestamp, but you don't need handle this argument in the web server.

What is cached network image?

Cached network imageA flutter library to show images from the internet and keep them in the cache directory.


1 Answers

Since CachedNetworkImage version 2.3, all these solutions won't work because it cached images in 2 different places (DefaultCacheManager & NetworkImageProvider)

So the only solution is using the evictFromCache built-in method from CachedNetworkImage

like this:

Future _deleteImageFromCache() async {
    String url = "your url";
    await CachedNetworkImage.evictFromCache(url);
  }

evictFromCache is a Static method so it doesn't require to have the CachedNetworkImage in your Widget tree, you can use it directly from any place.

like image 160
Abdelazeem Kuratem Avatar answered Oct 14 '22 14:10

Abdelazeem Kuratem