如何在Flutter中删除缓存和应用程序目录 [英] How to Delete cache and app dir in flutter
本文介绍了如何在Flutter中删除缓存和应用程序目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的flutter应用程序中,我将一些图像存储在缓存目录中,并将一些文件存储在应用程序文档目录中,现在我想给用户增加删除缓存目录和应用程序目录的可能性,我怎样才能做到这一点?
解决方案
您需要 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);
}
}
这篇关于如何在Flutter中删除缓存和应用程序目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文