Flutter有自己的内部图像缓存.我需要清除图像缓存.我该怎么做?

推荐答案

参考Flutter docs

/// This is the custom implementation of [ImageCache] where we can override
/// the logic.
class MyImageCache extends ImageCache {
  @override
  void clear() {
    print('Clearing cache!');
    super.clear();
  }
}

class MyWidgetsBinding extends WidgetsFlutterBinding {
  @override
  ImageCache createImageCache() => MyImageCache();
}

void main() {
  // The constructor sets global variables.
  MyWidgetsBinding();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Flutter相关问答推荐

UI中的Flutter 下拉列表值未更改

如何在Flutter 中共享选定文本

Android Studio扩展控件上未加载Google map

如何在不注销的情况下刷新Firebase身份验证用户

从.gitignore中排除.fvm/fvm_config.json

在创建显示此错误的Flutter 深度链接时

Flutter 附近的连接

将自定义容器附加到屏幕底部

如何在flutter中加载并显示adx锚定的自适应广告?

Flutter记录返回类型问题

课程中的访问Provider

Flutter蓝牙 - 如何通过蓝牙从设备中获取文件?

允许文本小部件在容器之间溢出

围绕父组件旋转位置组件

如何防止键盘将内容向上推?

SfCircularChart 周围的额外间距

Flutter 中出现错误空判断运算符用于空值

Flutter:当我通过 Transform.rotate 旋转水平 ListView 时,左右边缘被切断

无法在Flutter 图像小部件中打开大尺寸(500MB)图像

仅使用 Flutter 在本地环境中托管 Web 服务器