openDatabase abstract method

Future<Database> openDatabase(
  1. String path, {
  2. OpenDatabaseOptions? options,
})

Open a database at path with the given OpenDatabaseOptionsoptions

A relative path is relative to getDatabasesPath. Open a database once and keep the returned Database, see OpenDatabaseOptions.new for the options and the callbacks.

var path = join(await factory.getDatabasesPath(), 'demo.db');
var db = await factory.openDatabase(
  path,
  options: OpenDatabaseOptions(
    version: 1,
    onCreate: (db, version) async {
      // When creating the db, create the table
      await db.execute(
        'CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, num REAL)',
      );
    },
  ),
);

Notice, join is a part of the path package

Implementation

Future<Database> openDatabase(String path, {OpenDatabaseOptions? options});