Flutter_cached_network_image: How to reload image from cache

Created on 13 Jul 2019  路  9Comments  路  Source: Baseflow/flutter_cached_network_image

Hi,

I have a user profile, I change the image BUT how can I refresh that user photo url so it can get the new one?

Thank you

Most helpful comment

I am using

cached_network_image: ^2.0.0
flutter_cache_manager: ^1.1.3

and still cannot get the cache to be deleted. I even tried
DefaultCacheManager().emptyCache();
but still get the old image.

What could I be doing wrong?

All 9 comments

One solution would be to use a new URL for a new image. In my opinion that is the correct solution. If a user changes their profile picture, I would consider that to be a new resource. Because it is is a new resource, I think it should have a new resource locator (i.e. new URI).

That depends on how the API was designed. In my case, the image URL is always /users/123/avatar, just like my user is always /users/123. I can update both resources, but their URLs stay the same.

Either way, changing the backend is not feasible right now, it would be good if clearing the cache had an effect :)

You can clear the cached image by calling on the cachemanager directly, but for that you have to know when the image changes. You can call DefaultCacheManager().removeFile(url)

See https://pub.dev/documentation/flutter_cache_manager/latest/flutter_cache_manager/DefaultCacheManager-class.html

I've called emptyCache() to clear everything, but the CircleAvatar didn't reload from the CachedNetworkImageProvider, even when I changed the avatar widget's key. I'll try using a CachedImageWidget and/or removeFile() later. How these things work together could be useful information to have in the README.

DefaultCacheManager().removeFile(photoUrl); don't work, don't know what is DefaultCacheManager()

Am I missing some import?

@FilipeOS If you add flutter_cache_manager to your pubspec, Android Studio will let you automatically import it.

@jlnr sorry but why should I import if I have cached_network_image on pubspec already?

There was something wrong in the link between the cache manager and the image widget. Because of that images already in memory were not refreshed. Should be fixed in the latest release, if not please re-open this issue.

I am using

cached_network_image: ^2.0.0
flutter_cache_manager: ^1.1.3

and still cannot get the cache to be deleted. I even tried
DefaultCacheManager().emptyCache();
but still get the old image.

What could I be doing wrong?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

srburton picture srburton  路  6Comments

yossefEl picture yossefEl  路  4Comments

sososdk picture sososdk  路  5Comments

nashfive picture nashfive  路  5Comments

anass-naoushi picture anass-naoushi  路  5Comments