【问题标题】:How do I clear Flutter's image cache?如何清除 Flutter 的图片缓存?
【发布时间】:2018-04-22 21:43:18
【问题描述】:

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

【问题讨论】:

  • 哇,使用 SO 作为在线文档是个好主意
  • 是吗?!我认为最好保持这个网站的用途。如果您想要一个常见问题解答,请创建一个常见问题解答,如果您想要一个文档,请编写一个文档。我希望我的文档在我的 IDE 中而不是在 SO... 我不认为提出的问题会使这个网站变得更好。我想从使用该语言的开发人员那里得到问题,并从制作它的人那里得到答案。如果有一个问题出现了很多次或者得到了更多的支持,那么他们的产品或他们的文档可能存在一些问题,应该修复......
  • 我缺乏将讽刺/拖钓与严肃答案区分开来的能力。我只希望第一个答案是讽刺,第二个错误地解释为严肃。

标签: dart flutter


【解决方案1】:

参考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();
  }
}

【讨论】:

  • 为什么不暴露在颤振医生的手下?
  • 因为这个答案也是由赛斯编辑的,所以看了一秒钟,好像他也回答了一样。因为我最近看到的 4 个问题中有 3 个是 Seth 的,所以我会说这个策略是有效的。谢谢
猜你喜欢
  • 2012-05-04
  • 2011-05-21
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
  • 2010-12-27
  • 1970-01-01
  • 2019-06-10
相关资源
最近更新 更多