openDatabase method

  1. @override
Future<void> openDatabase(
  1. String dbName
)
override

Implementation

@override
Future<void> openDatabase(String dbName) async {

  // Check if platform is web or mobile in order to use the right underlining library and DB. Web uses indexedDB. Mobile uses single file in local storage
  if (kIsWeb) {
    // Open the database
    db = await databaseFactoryWeb.openDatabase(dbName);
  } else {
    // get the application documents directory
    var dir = await getApplicationDocumentsDirectory();
    // make sure it exists
    await dir.create(recursive: true);
    // build the database path
    var dbPath = join(dir.path, '$dbName.db');
    // open the database
    db = await databaseFactoryIo.openDatabase(dbPath);
  }
}