|
|
|
@ -31,26 +31,31 @@ class SqfliteModel extends Model {
|
|
|
|
|
|
|
|
|
|
/// Init database |
|
|
|
|
Future<void> init() async { |
|
|
|
|
// Get a location using getDatabasesPath |
|
|
|
|
var databasesPath = await getDatabasesPath(); |
|
|
|
|
String path = p.join(databasesPath, 'demo.db'); |
|
|
|
|
|
|
|
|
|
// Delete the database |
|
|
|
|
await deleteDatabase(path); |
|
|
|
|
|
|
|
|
|
// open the database |
|
|
|
|
_db = await openDatabase( |
|
|
|
|
path, |
|
|
|
|
version: 1, |
|
|
|
|
onCreate: (Database db, int version) async { |
|
|
|
|
// When creating the db, create the table |
|
|
|
|
await db.execute('''CREATE TABLE Test ( |
|
|
|
|
try { |
|
|
|
|
// Get a location using getDatabasesPath |
|
|
|
|
var databasesPath = await getDatabasesPath(); |
|
|
|
|
String path = p.join(databasesPath, 'demo.db'); |
|
|
|
|
|
|
|
|
|
// Delete the database |
|
|
|
|
await deleteDatabase(path); |
|
|
|
|
|
|
|
|
|
// open the database |
|
|
|
|
_db = await openDatabase( |
|
|
|
|
path, |
|
|
|
|
version: 1, |
|
|
|
|
onCreate: (Database db, int version) async { |
|
|
|
|
// When creating the db, create the table |
|
|
|
|
await db.execute('''CREATE TABLE Test ( |
|
|
|
|
name TEXT, |
|
|
|
|
value INTEGER, |
|
|
|
|
num REAL |
|
|
|
|
)'''); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} catch (e) { |
|
|
|
|
_error = e.toString(); |
|
|
|
|
} |
|
|
|
|
notifyListeners(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Close database |
|
|
|
|