Flutter 使用image.network时从缓存中删除图像

Flutter 使用image.network时从缓存中删除图像,flutter,Flutter,Im使用Image.Network根据URL显示图像: ClipOval( child: Image.network( 'http://myurl${userId}.png', width: 100, height:

Im使用Image.Network根据URL显示图像:

ClipOval(
                                  child: Image.network(
                                    'http://myurl${userId}.png',
                                    width: 100,
                                    height: 100,
                                    fit: BoxFit.cover,
                                    key: profileImageKey,
                                  ),
                                ),
我试图让用户上传一个新的配置文件图像,但是,我保留了相同的文件名(userid+.png)。一旦用户上传了图像,上面的显示屏就不会显示新图像

我已尝试使用以下方法重建小部件:

setState(() {
                                            //generateKey();
                                            profileImageKey = ValueKey(new Random().nextInt(100));
                                            userId = userId;
                                          });
我还尝试使用以下方法从缓存中删除url:

PaintingBinding.instance.imageCache.evict('http://myurl${userId}.png');
然而,这些方法都不起作用。是否有方法更新映像。网络下载并使用上载的新映像


基于@pskink的评论,谢谢

这个问题的解决方案是在图像上使用逐出方法。因此,我将代码重构为:

Image profileImage;


好的,明白了,我需要对图像本身调用execute。谢谢
new Random()。nextInt(100)
不是一个好主意-你需要一个真正唯一的密钥-Random不提供这一功能。我可以做其他功能吗?@pskink不幸的是,驱逐对我不起作用。我想是的,但是在第一次上传之后,第二次上传以及之后的任何事情都不起作用。我甚至在我的服务器(firebase存储)上物理删除了该文件,因为它仍在显示我的个人资料图像。假设这仍然在缓存中。
profileImage = Image.network(
                                    'http://myurl${userId}.png',
                                    width: 100,
                                    height: 100,
                                    fit: BoxFit.cover,
                                    key: profileImageKey,
                                  );
ClipOval(
                                  child: profileImage,
                                ),
profileImage.image.evict();
                                              
                                              setState(() {
                                                //generateKey();
                                                profileImageKey = ValueKey(new Random().nextInt(100));
                                                userId = userId;
                                              });