如何在Flutter上以编程方式清除应用程序缓存

如何在Flutter上以编程方式清除应用程序缓存

问题描述:

因为我一直在使用Flutter开发应用程序.我发现应用程序的体积很大,而且它占用大量空间作为应用程序数据和应用程序缓存.有什么方法可以通过编程方式清除应用程序缓存吗?

As I have been developing app using Flutter. I came to find that app is heavy in size plus it is using a lot of space as app data and app cache. Is there any way to clear app cache programmatically?

在发布模式下,我的应用程序大小约为7mb,应用程序数据约为11mb.我的应用程序在应用程序内打开了一个站点,并且还流播了在线广播,因此其应用程序数据还在不断增加

my app's size in release mode is about 7mb and app data is about 11mb. My app opens one site within app and it also streams online radio so it's app data goes on increasing

您可以获取temp文件夹,然后删除其中的文件.

You can get the temp folder, and delete files in it.

var appDir = (await getTemporaryDirectory()).path;
new Directory(appDir).delete(recursive: true);