更新时间:2022-11-04 19:53:11
您需要 path_provider 包>
然后尝试以下代码:
Future< void>_deleteCacheDir()异步{最后的cacheDir =等待getTemporaryDirectory();如果(cacheDir.existsSync()){cacheDir.deleteSync(recursive:true);}}Future< void>_deleteAppDir()异步{最后的appDir =等待getApplicationSupportDirectory();if(appDir.existsSync()){appDir.deleteSync(recursive:true);}}
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?
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);
}
}