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