NetworkImage正在缓存旧图像 [英] NetworkImage is caching the old image
本文介绍了NetworkImage正在缓存旧图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 NetworkImage
类显示来自互联网的图像,以下是代码
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,
),
),
);
但是缓存了图像,并且在服务器上更新图像时,应用程序显示旧的缓存的图像。
如何停止 NetworkImage
上的缓存?
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
?
推荐答案
您可以使用以下网址逐出从URL加载的图像
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!');
});
}
或者您也可以在URL中添加随机查询部分
or alternatively you can add a random query part to the URL
int counter = 0;
...
NetworkImage('https://example.com/images/image1.png?dummy=${counter++}');
这篇关于NetworkImage正在缓存旧图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文