Skip to content

Commit

Permalink
db: Revert 'revert of #252'
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Dec 10, 2023
1 parent e284f00 commit 9fed12c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class DataBaseManager {

@protected
@mustCallSuper
void dispose() async {
Future<void> dispose() async {
print('close: ${dbPath!}');
if (db != null) db!.close();
await db?.close();
db = null;
}

static Future<DataBaseManager> getInstance() async {
Expand All @@ -43,20 +44,17 @@ class DataBaseManager {
}

static Future<void> 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<void> open() async {
db ??= await openDatabase(dbPath!);
}

Future checkOpen() async {
if(db != null){
if (!db!.isOpen) db = await openDatabase(dbPath!);
} else if(db == null){
Future<void> checkOpen() async {
if (!(db?.isOpen ?? false)) {
db = await openDatabase(dbPath!);
}
}
Expand Down

0 comments on commit 9fed12c

Please sign in to comment.