How to clear flutter desktop app data like flutter mobile app

Issue

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

Solution

 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

Answered By – Mahmood Ali

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *