Workaround sqlite library not loading on some Android 6 or below devices

This commit is contained in:
Ming Ming 2022-08-15 01:40:44 +08:00
parent af16734fb6
commit 42a8539fb6

View file

@ -37,6 +37,7 @@ import 'package:nc_photos/platform/features.dart' as features;
import 'package:nc_photos/platform/k.dart' as platform_k; import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart'; import 'package:nc_photos/pref.dart';
import 'package:nc_photos/pref_util.dart' as pref_util; import 'package:nc_photos/pref_util.dart' as pref_util;
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
import 'package:visibility_detector/visibility_detector.dart'; import 'package:visibility_detector/visibility_detector.dart';
enum InitIsolateType { enum InitIsolateType {
@ -54,11 +55,14 @@ Future<void> init(InitIsolateType isolateType) async {
} }
initLog(); initLog();
await _initDeviceInfo();
initDrift(); initDrift();
if (isolateType == InitIsolateType.main) {
await _initDriftWorkaround();
}
_initKiwi(); _initKiwi();
await _initPref(); await _initPref();
await _initAccountPrefs(); await _initAccountPrefs();
await _initDeviceInfo();
_initEquatable(); _initEquatable();
if (features.isSupportSelfSignedCert) { if (features.isSupportSelfSignedCert) {
_initSelfSignedCertManager(); _initSelfSignedCertManager();
@ -117,6 +121,15 @@ void initDrift() {
driftRuntimeOptions.debugPrint = (log) => debugPrint(log, wrapWidth: 1024); driftRuntimeOptions.debugPrint = (log) => debugPrint(log, wrapWidth: 1024);
} }
Future<void> _initDriftWorkaround() async {
if (AndroidInfo().sdkInt < 24) {
_log.info("[_initDriftWorkaround] Workaround Android 6- bug");
// see: https://github.com/flutter/flutter/issues/73318 and
// https://github.com/simolus3/drift/issues/895
await applyWorkaroundToOpenSqlite3OnOldAndroidVersions();
}
}
Future<void> _initPref() async { Future<void> _initPref() async {
final provider = PrefSharedPreferencesProvider(); final provider = PrefSharedPreferencesProvider();
await provider.init(); await provider.init();