gpt4 book ai didi

dart - 如何清除 Flutter 的图片缓存?

转载 作者:IT老高 更新时间:2023-10-28 12:29:05 25 4
gpt4 key购买 nike

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

关于dart - 如何清除 Flutter 的图片缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47209606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com