Skip to content

Commit

Permalink
Fix Linux / Windows error (#5431)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jun 22, 2024
1 parent 60a898f commit eb03ed1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/smooth_app/lib/database/local_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb03ed1

Please sign in to comment.