In my flutter app, I store some images in cache directory and some files in application document directory, now I want to add possibility to my users to delete the cache dir and app dir, How can I achieve this?
Go to Tools > Flutter > Flutter Clean to clear the build cache of the Flutter project.
You can run rm -rf ~/flutter/bin/cache in the terminal to clear the Flutter bin cache.
Step 1: Create a new project and launch main. dart file. Clear the existing code. import 'package:flutter/material.
You need path_provider package
Then try this code:
Future<void> _deleteCacheDir() async {
final cacheDir = await getTemporaryDirectory();
if (cacheDir.existsSync()) {
cacheDir.deleteSync(recursive: true);
}
}
Future<void> _deleteAppDir() async {
final appDir = await getApplicationSupportDirectory();
if(appDir.existsSync()){
appDir.deleteSync(recursive: true);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With