问题
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