connect static method
Establish the connection
Implementation
static Future<void> connect() async {
print("[GeigerToolboxAPIs] Connecting to database");
// Avoid errors caused by flutter upgrade.
// Importing 'package:flutter/widgets.dart' is required.
WidgetsFlutterBinding.ensureInitialized();
// Open the database and store the reference.
GeigerToolboxAPIs.database = openDatabase(
// Set the path to the database. Note: Using the `join` function from the
// `path` package is best practice to ensure the path is correctly
// constructed for each platform.
join(await getDatabasesPath(), GeigerConfigs.DB_NAME),
// When the database is first created, create a table to store dogs.
onCreate: (db, version) {
// Run the CREATE TABLE statement on the database.
return db.execute(
'CREATE TABLE ${GeigerConfigs.DB_SENSING_DATA_TABLE}(key TEXT PRIMARY KEY, value TEXT)',
);
},
// Set the version. This executes the onCreate function and provides a
// path to perform database upgrades and downgrades.
version: 1,
);
}