Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear app cache programmatically on Flutter

Tags:

flutter

dart

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

like image 718
DoeJ Avatar asked Nov 14 '18 09:11

DoeJ


People also ask

How do I clear app cache programmatically in flutter?

Go to Tools > Flutter > Flutter Clean to clear the build cache of the Flutter project.

How do I clear app storage flutter?

0" Then follow the steps: Run flutter upgrade in the terminal to upgrade Flutter Run dart migrate to run the dart migration tool. Solve all errors which the migration tool shows. Run flutter pub outdated --mode=null.

How do I clear cached Cachednetworkimage flutter?

Use the DefaultCacheManager object by calling emptyCache() method, this clears the cache data. DefaultCacheManager manager = new DefaultCacheManager(); manager. emptyCache(); //clears all data in cache.


2 Answers

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

var appDir = (await getTemporaryDirectory()).path;
new Directory(appDir).delete(recursive: true);
like image 177
Vincent Avatar answered Sep 21 '22 07:09

Vincent


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();
like image 31
Shubhamhackz Avatar answered Sep 19 '22 07:09

Shubhamhackz