Browse Source

[example] Add catch sqflite

embedder_texture
Vitaliy Zarubin 1 year ago
parent
commit
3413ecd9a3
  1. 37
      example/lib/packages/sqflite/model.dart

37
example/lib/packages/sqflite/model.dart

@ -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

Loading…
Cancel
Save