ensureDatabase method

Future<void> ensureDatabase()

Implementation

Future<void> ensureDatabase() async {
  var db = _db;
  if (db != null && db.isOpen) {
    return;
  }

  _db = await open(kDatabaseName);
  db = _db;
  if (db != null) {
    List<Map>? result = await db.rawQuery(
        "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name = '$kTableStorage'", null);
    if (result.isNotEmpty) {
      return;
    }
    db.execute(kStatementCreateTable);
  }
}