How to implement Flutter App clear user app data and storage on logout.. i want to clear everything (shared preferences, global variables, singletons, local storage, cache) this should be equivalent to Android > settings > App > clear storage & clear cache..
Open android studio Tools->Flutter->Clean. Go to File -> Invalidate Caches / Restart.
Go to Tools > Flutter > Flutter Clean to clear the build cache of the Flutter project.
Periodic timer is used to execute callback repeatedly (e.g., every 10 seconds); Timer sets when the widget initializes and when any tap happens. Any following tap will cancel the old timer and create a new one.
first install 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);
    }
}
see the original answer here
you must use from path_provider to get your app TemporaryDirectory and app Directory on the filesystem.
    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);
      }
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With