diff --git a/lib/database/database.dart b/lib/database/database.dart index dd4373388..efd1edf6e 100644 --- a/lib/database/database.dart +++ b/lib/database/database.dart @@ -20,9 +20,10 @@ class DataBaseManager { @protected @mustCallSuper - void dispose() async { + Future dispose() async { print('close: ${dbPath!}'); - if (db != null) db!.close(); + await db?.close(); + db = null; } static Future getInstance() async { @@ -37,18 +38,19 @@ class DataBaseManager { } static Future reloadInstance() async { - var dbPath = Platform.isAndroid - ? '${(await getApplicationDocumentsDirectory()).path}/data/data.db' - : '${await getDatabasesPath()}/data.db'; - _instance = create(dbPath); + final db = _instance?.db; + _instance?.db = null; + await db?.close(); } - Future open() async { + Future open() async { db ??= await openDatabase(dbPath!); } - Future checkOpen() async { - if (!db!.isOpen) db = await openDatabase(dbPath!); + Future checkOpen() async { + if (!(db?.isOpen ?? false)) { + db = await openDatabase(dbPath!); + } } Future>> query(String str) async {