How to clear flutter desktop app data like flutter mobile app

Viewed 1039

i'm working on flutter desktop app and i want to clear app database, Like as we do on mobile, we go to app settings and clear cache and data, to reset app settings. Likewise i want to do the same with desktop app. Can anyone help me how to do that?

Thanks

4 Answers

I was able to fix this in Linux by deleting the flutter_app_directory found in ~/.local/share/<flutter_app_name>

Similar actions can be found in Windows and MacOS

 return LazyDatabase(
    () async {
      var dbFolderPath = '';
      if (GetPlatform.isDesktop) {
        final provider = PathProviderWindows();
        dbFolderPath = (await provider.getApplicationSupportPath())!;
      } else {
        final dbFolder = await getApplicationDocumentsDirectory();
        dbFolderPath = dbFolder.path;
      }

      final file = File(path.join(dbFolderPath, _databaseName));
      debugPrint(file.path);
      return NativeDatabase(file);
    },
  );

Just print the path of your database and you will know exactly where it is stored, for me, its store on this path

flutter: C:\Users\USERNAME\AppData\Roaming\PACKAGE_NAME\debt_record\db.sqlite

for macos i had to open finder then hit command + shift + g and paste this

~/Library/Application Support

and in app package folder I found all the files

My issue was with Hive on Windows, I managed to solve it with the following solution (i think it works on other platforms as well) :

 await Hive.initFlutter();

 var appDir = await getApplicationDocumentsDirectory();
 print(appDir);

also don't forget to import the path provider as follow:

import 'package:path_provider/path_provider.dart';

you will get something like this on the debug console

C:\Users\USERNAME\Documents

when you navigate to that directory you will find the files you need, for hive, I found all the boxes files like box_name.hive and box_name.lock so I deleted the files related to my issue is solved

this would work with all the other storage packages as well

Related