Search code examples
fluttersqlitemobile

Flutter: sqflite DB


A local database is created in the code. Where will it be located?


class DatabaseHelper {
  
  final databaseName = "app.db";
  String users =
      "create table users (userId INTEGER PRIMARY KEY AUTOINCREMENT, userName TEXT UNIQUE, userPassword TEXT)";
  Future<Database> initDB() async {
    final databasePath = await getDatabasesPath();
    final path = join(databasePath, databaseName);

    return openDatabase(path, version: 1, onCreate: (db, version) async {
      await db.execute(users);
     // await db.execute(noteTable);
    });
  }
}

Everything is working fine, but how can I open it outside the application?


Solution

  • Where will it be located?

    It will located in the data/data/<the_package_name>/databases folder.

    • note that in addition to the app.db file, an app.db-wal and an app.db-shm file may also exist. If the app.db-wal file is not empty then this is part of the database.

    Everything is working fine, but how can I open it outside the application?

    The file(s) are in protected storage so normally they cannot be accessed outside of the App. If using an Android Studio emulator then you can access the database via App Inspector or via Device Explorer (which would allow the file(s) to be copied).