From 772ff33d8ec6dbaaa67e28b1cc9870bc84839328 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 4 Oct 2020 18:21:56 +0200 Subject: [PATCH] fix: Linux database --- lib/utils/database/mobile.dart | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/utils/database/mobile.dart b/lib/utils/database/mobile.dart index d424e5f2..30a2a75b 100644 --- a/lib/utils/database/mobile.dart +++ b/lib/utils/database/mobile.dart @@ -2,6 +2,7 @@ import 'dart:ffi'; import 'dart:io'; import 'dart:isolate'; import 'package:famedlysdk/famedlysdk.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:sqflite/sqflite.dart' show getDatabasesPath; import 'package:path/path.dart' as p; import 'package:flutter/material.dart'; @@ -64,22 +65,17 @@ Future constructDb( final isolate = (await receivePort.first as MoorIsolate); return Database.connect(await isolate.connect()); } else if (Platform.isLinux) { - debugPrint('[Moor] using desktop moor'); - open.overrideFor(OperatingSystem.linux, _openOnLinux); - return Database(moor.VmDatabase.memory()); + debugPrint('[Moor] using Linux desktop moor'); + final appDocDir = await getApplicationSupportDirectory(); + return Database(moor.VmDatabase(File('${appDocDir.path}/$filename'))); } else if (Platform.isWindows) { - debugPrint('[Moor] using desktop moor'); - open.overrideFor(OperatingSystem.linux, _openOnWindows); + debugPrint('[Moor] using Windows desktop moor'); + open.overrideFor(OperatingSystem.windows, _openOnWindows); return Database(moor.VmDatabase.memory()); } throw Exception('Platform not supported'); } -DynamicLibrary _openOnLinux() { - final libraryNextToScript = File('/usr/lib/x86_64-linux-gnu/libsqlite3.so'); - return DynamicLibrary.open(libraryNextToScript.path); -} - DynamicLibrary _openOnWindows() { final script = File(Platform.script.toFilePath()); final libraryNextToScript = File('${script.path}/sqlite3.dll');