首页 > 解决方案 > 如何实现 Flutter 在注销时清除用户应用数据和存储

问题描述

如何实现 Flutter App 在注销时清除用户应用数据和存储.. 我想清除所有内容(共享首选项、全局变量、单例、本地存储、缓存)这应该相当于 Android > 设置 > 应用 > 清除存储和清除缓存..

标签: flutter

解决方案


首先安装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);
    }
}

在此处查看原始答案


推荐阅读