diff --git a/app/lib/app_init.dart b/app/lib/app_init.dart index f910d8dd..7a2c13f3 100644 --- a/app/lib/app_init.dart +++ b/app/lib/app_init.dart @@ -188,10 +188,12 @@ void _initVisibilityDetector() { Future _createDb(InitIsolateType isolateType) async { final npDb = NpDb(); + final androidSdk = + getRawPlatform() == NpPlatform.android ? AndroidInfo().sdkInt : null; if (isolateType == InitIsolateType.main) { - await npDb.initMainIsolate(androidSdk: AndroidInfo().sdkInt); + await npDb.initMainIsolate(androidSdk: androidSdk); } else { - await npDb.initBackgroundIsolate(androidSdk: AndroidInfo().sdkInt); + await npDb.initBackgroundIsolate(androidSdk: androidSdk); } return npDb; } diff --git a/np_db/lib/src/api.dart b/np_db/lib/src/api.dart index 1b438642..f99ef2ae 100644 --- a/np_db/lib/src/api.dart +++ b/np_db/lib/src/api.dart @@ -100,12 +100,22 @@ class DbLocationGroupResult { abstract class NpDb { factory NpDb() => NpDbSqlite(); + /// Initialize the db for the main isolate + /// + /// If running on android, you must pass the current SDK int to [androidSdk]. + /// If running on other platforms, this value will be ignored, you can pass + /// null in such case Future initMainIsolate({ - required int androidSdk, + required int? androidSdk, }); + /// Initialize the db for a background isolate + /// + /// If running on android, you must pass the current SDK int to [androidSdk]. + /// If running on other platforms, this value will be ignored, you can pass + /// null in such case Future initBackgroundIsolate({ - required int androidSdk, + required int? androidSdk, }); /// Dispose the db diff --git a/np_db_sqlite/lib/src/sqlite_api.dart b/np_db_sqlite/lib/src/sqlite_api.dart index 4b5cde78..67cabdeb 100644 --- a/np_db_sqlite/lib/src/sqlite_api.dart +++ b/np_db_sqlite/lib/src/sqlite_api.dart @@ -26,10 +26,10 @@ class NpDbSqlite implements NpDb { @override Future initMainIsolate({ - required int androidSdk, + required int? androidSdk, }) async { initDrift(); - if (getRawPlatform() == NpPlatform.android && androidSdk < 24) { + if (getRawPlatform() == NpPlatform.android && androidSdk! < 24) { _log.info("[initMainIsolate] Workaround Android 6- bug"); // see: https://github.com/flutter/flutter/issues/73318 and // https://github.com/simolus3/drift/issues/895 @@ -47,7 +47,7 @@ class NpDbSqlite implements NpDb { @override Future initBackgroundIsolate({ - required int androidSdk, + required int? androidSdk, }) async { initDrift(); // service already runs in an isolate