在我的 flutter 应用程序中,我将一些图像存储在缓存目录中,将一些文件存储在应用程序文档目录中,现在我想为我的用户添加删除缓存目录和应用程序目录的可能性,我该如何实现?
小智 24
你需要path_provider包
然后试试这个代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8622 次 |
| 最近记录: |