diff --git a/lib/flutter_data.dart b/lib/flutter_data.dart index 5157e820..ef3e8688 100644 --- a/lib/flutter_data.dart +++ b/lib/flutter_data.dart @@ -3,6 +3,7 @@ library flutter_data; // import external packages import 'dart:async'; import 'dart:convert'; +import 'dart:ffi'; import 'dart:io'; import 'dart:isolate'; import 'dart:math' show Random; @@ -15,6 +16,7 @@ import 'package:inflection3/inflection3.dart' as inflection; import 'package:meta/meta.dart'; import 'package:path/path.dart' as path_helper; import 'package:riverpod/riverpod.dart'; +import 'package:sqlite3/open.dart'; import 'package:sqlite3/sqlite3.dart'; import 'package:state_notifier/state_notifier.dart'; diff --git a/lib/src/storage/local_storage.dart b/lib/src/storage/local_storage.dart index 841d10bd..b9aacdcc 100644 --- a/lib/src/storage/local_storage.dart +++ b/lib/src/storage/local_storage.dart @@ -29,6 +29,10 @@ class LocalStorage { await destroy(); } + if (Platform.isWindows) { + open.overrideFor(OperatingSystem.windows, _openOnWindows); + } + db = sqlite3.open(path, mutex: false); if (inIsolate) { @@ -109,3 +113,12 @@ enum LocalStorageClearStrategy { final localStorageProvider = Provider( (ref) => LocalStorage(baseDirFn: () => ''), ); + +// platforms + +DynamicLibrary _openOnWindows() { + final scriptDir = File(Platform.script.toFilePath()).parent; + final libraryNextToScript = + File(path_helper.join(scriptDir.path, 'sqlite3.dll')); + return DynamicLibrary.open(libraryNextToScript.path); +}