假设我在设备磁盘上有一个图像并将其加载到屏幕上,并提供其到FileImage.
我编辑该图像并将其保存在同一路径上,期望调用该setState(() {})函数将重新加载它。但事实并非如此。
我尝试通过调用imageCache.clear()函数清除图像缓存,imageProvider.evict()但也没有区别。
如果我关闭该页面并再次打开它,我会看到更新的图像。
我假设屏幕上显示的图像在内存中,如果我的假设正确,如何重新加载它?
我知道我有点晚了,但我使用了这个解决方法:
_tmpImageFile.existsSync() ? Image.memory(
Uint8List.fromList(_tmpImageFile.readAsBytesSync()),
alignment: Alignment.center,
height: 200,
width: 200,
fit: BoxFit.contain,
) : Container(),
Run Code Online (Sandbox Code Playgroud)
改变图像的键可以解决问题吗?
设置图像的关键点
Image.file(
_imageFile,
key: _key,
fit: BoxFit.cover,
),
Run Code Online (Sandbox Code Playgroud)
并在每次更改 _imageFile 时更改密钥,例如让我们将其设置为时间戳
setState(() {
_imageFile = newImageFile;
_key = DateTime.now().millisecondsSinceEpoch;
});
Run Code Online (Sandbox Code Playgroud)