flutter - 如何实现 Flutter 在注销时清除用户应用数据和存储
问题描述
如何实现 Flutter App 在注销时清除用户应用数据和存储.. 我想清除所有内容(共享首选项、全局变量、单例、本地存储、缓存)这应该相当于 Android > 设置 > 应用 > 清除存储和清除缓存..
解决方案
首先安装path_provider
/// this will delete cache
Future<void> _deleteCacheDir() async {
final cacheDir = await getTemporaryDirectory();
if (cacheDir.existsSync()) {
cacheDir.deleteSync(recursive: true);
}
}
/// this will delete app's storage
Future<void> _deleteAppDir() async {
final appDir = await getApplicationSupportDirectory();
if(appDir.existsSync()){
appDir.deleteSync(recursive: true);
}
}
在此处查看原始答案
推荐阅读
- c# - 无法转换类型异常的对象
- r - 如何使用公开数据将字符串转换为 R 中的数值
- javascript - 从单页转换为多页应用程序后未加载数据
- javascript - 使用 React Native 运行繁重的 JS 任务
- dart - 用画布理解动画
- xamarin - 如何更改 Xamarin Forms 中的文本颜色状态栏?
- vb.net - 带有 DataGridView 的 VB .net
- python - 如何检查python中最长的子字符串
- linq - SQL 到 Linq 的转换 - Max()、Groupby、Limit/page
- regex - Scala正则表达式匹配字符串中的单词之间和之后