【问题标题】:How to implement Flutter clear user app data and storage on logout如何实现 Flutter 在注销时清除用户应用数据和存储
【发布时间】:2020-10-14 06:46:19
【问题描述】:

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

【问题讨论】:

标签: flutter


【解决方案1】:

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

查看原答案here

【讨论】:

    【解决方案2】:

    您必须使用 from path_provider 来获取您的应用程序 TemporaryDirectory 和应用程序目录 在文件系统上。

        import 'dart:io';
        import 'package:path_provider/path_provider.dart';
        
        Future<void> _deleteCacheDir() async {
        Directory tempDir = await getTemporaryDirectory();
        
          if (tempDir.existsSync()) {
            tempDir.deleteSync(recursive: true);
          }
        }
        
        Future<void> _deleteAppDir() async {
         Directory appDocDir = await getApplicationDocumentsDirectory();
    
          if (appDocDir.existsSync()) {
            appDocDir.deleteSync(recursive: true);
          }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-02-16
      • 2019-01-27
      • 1970-01-01
      • 2019-06-19
      • 2022-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      相关资源
      最近更新 更多