From 3413ecd9a32feb820b4977d0b5f447635f783e9e Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Fri, 13 Oct 2023 08:04:31 +0300 Subject: [PATCH] [example] Add catch sqflite --- example/lib/packages/sqflite/model.dart | 37 ++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/example/lib/packages/sqflite/model.dart b/example/lib/packages/sqflite/model.dart index 774f197..95fe757 100644 --- a/example/lib/packages/sqflite/model.dart +++ b/example/lib/packages/sqflite/model.dart @@ -31,26 +31,31 @@ class SqfliteModel extends Model { /// Init database Future 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