Fix Linux / Windows error (#5431)

This commit is contained in:
Edouard Marquez
2024-06-22 08:48:23 +02:00
committed by GitHub
parent 60a898f51e
commit eb03ed1ecf
3 changed files with 25 additions and 4 deletions

View File

@ -21,7 +21,7 @@ import 'package:smooth_app/database/dao_string_list.dart';
import 'package:smooth_app/database/dao_string_list_map.dart';
import 'package:smooth_app/database/dao_transient_operation.dart';
import 'package:smooth_app/database/dao_work_barcode.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
class LocalDatabase extends ChangeNotifier {
LocalDatabase._(final Database database) : _database = database {
@ -53,14 +53,18 @@ class LocalDatabase extends ChangeNotifier {
static Future<LocalDatabase> getLocalDatabase() async {
// sql from there
final String databasesRootPath;
String? databasesRootPath;
if (defaultTargetPlatform == TargetPlatform.iOS) {
// as suggested in https://pub.dev/documentation/sqflite/latest/sqflite/getDatabasesPath.html
final Directory directory = await getLibraryDirectory();
databasesRootPath = directory.path;
} else {
databasesRootPath = await getDatabasesPath();
} else if (Platform.isLinux || Platform.isWindows) {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
}
databasesRootPath ??= await getDatabasesPath();
final String databasePath = join(databasesRootPath, 'smoothie.db');
final Database database = await openDatabase(
databasePath,

View File

@ -1523,6 +1523,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.5.4"
sqflite_common_ffi:
dependency: "direct main"
description:
name: sqflite_common_ffi
sha256: "4d6137c29e930d6e4a8ff373989dd9de7bac12e3bc87bce950f6e844e8ad3bb5"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
sqlite3:
dependency: transitive
description:
name: sqlite3
sha256: "1abbeb84bf2b1a10e5e1138c913123c8aa9d83cd64e5f9a0dd847b3c83063202"
url: "https://pub.dev"
source: hosted
version: "2.4.2"
stack_trace:
dependency: transitive
description:

View File

@ -39,6 +39,7 @@ dependencies:
provider: 6.1.2
sentry_flutter: 7.18.0
sqflite: 2.3.3+1
sqflite_common_ffi: 2.3.3
url_launcher: 6.1.3
visibility_detector: 0.4.0+2
assorted_layout_widgets: 9.0.1