How to clear app cache programmatically on Flutter

纵饮孤独 提交于 2021-02-08 12:26:42

问题


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?

Edit: 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


回答1:


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

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



回答2:


You can also use use flutter_cache_manager to delete or remove your app's cache programatically.

After installing flutter_cache_manager , use this :

await DefaultCacheManager().emptyCache();



回答3:


Note on Vincent's answer.

Try to avoid clearing the device's temporary folder. It'll be saver to clear the app it's cache folder like:

var appDir = (await getTemporaryDirectory()).path + '/<package_name>';
new Directory(appDir).delete(recursive: true);


来源:https://stackoverflow.com/questions/53296899/how-to-clear-app-cache-programmatically-on-flutter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!