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