I am using NetworkImage
class to display an image from the internet, the following is the code
return new Container(
width: width,
height: height,
decoration: new BoxDecoration(
color: const Color(0xff7c94b6),
image: new DecorationImage(
image: NetworkImage(url, headers: {"Authorization": token}),
fit: fit,
),
borderRadius: new BorderRadius.all(new Radius.circular(150.0)),
border: new Border.all(
color: Color(AppColors.surfacePrimary.hex),
width: 0.0,
),
),
);
However the image is cached, and when the image is updated on the server, the application displays the old cached image.
How can I stop the caching on NetworkImage
?
Cached network imageA flutter library to show images from the internet and keep them in the cache directory.
A CacheManager to download and cache files in the cache directory of the app. Various settings on how long to keep a file can be changed. It uses the cache-control http header to efficiently retrieve files. The more basic usage is explained here.
Go to Tools > Flutter > Flutter Clean to clear the build cache of the Flutter project.
You can evict the image loaded from an URL using
void evictImage() {
final NetworkImage provider = NetworkImage(url);
provider.evict().then<void>((bool success) {
if (success)
debugPrint('removed image!');
});
}
or alternatively you can add a random query part to the URL
int counter = 0;
...
NetworkImage('https://example.com/images/image1.png?dummy=${counter++}');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With