Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop support #325

Open
andreassch opened this issue Jun 12, 2024 · 1 comment
Open

Desktop support #325

andreassch opened this issue Jun 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@andreassch
Copy link

Description

The app does not run under Linux. When launching the compiled executable, it throws the following exception:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: databaseFactory not initialized
databaseFactory is only initialized when using sqflite. When using `sqflite_common_ffi`
You must call `databaseFactory = databaseFactoryFfi;` before using global openDatabase API

#0      databaseFactory.<anonymous closure> (package:sqflite_common/src/sqflite_database_factory.dart:29)
#1      databaseFactory (package:sqflite_common/src/sqflite_database_factory.dart:33)
#2      getDatabasesPath (package:sqflite_common/sqflite.dart:105)
#3      BloodPressureModel._asyncInit (package:blood_pressure_app/model/blood_pressure/model.dart:23)
#4      BloodPressureModel.create (package:blood_pressure_app/model/blood_pressure/model.dart:74)
#5      _loadApp (package:blood_pressure_app/main.dart:37)
#6      main (package:blood_pressure_app/main.dart:27)
#7      _runMain.<anonymous closure> (dart:ui/hooks.dart:301)
#8      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297)
#9      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

Android version

Debian Linux 12

Reproduction steps

1. Compile the app with `flutter build linux --release`.
2. Launch the app with `build/linux/x64/release/bundle/blood_pressure_app`.
3. The exception described above is thrown.

Screenshots & Settings backup

No response

App debug info

No response

@andreassch andreassch added the bug Something isn't working label Jun 12, 2024
@NobodyForNothing
Copy link
Owner

NobodyForNothing commented Jun 13, 2024

Currently no platform besides android is supported due to native dependencies.

To get linux builds running:

  1. In pubspec.yaml: move sqflite_common_ffi: ^2.3.0 from dev_dependencies to dependencies
  2. in lib/main.dart (app.dart after latest pr) add the import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import
  3. below WidgetsFlutterBinding.ensureInitialized() add
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
  databaseFactory = databaseFactoryFfi;
}

From my quick testing this works surprisingly well, but be weary of things that involve native code (for example deleting data).

@NobodyForNothing NobodyForNothing added enhancement New feature or request and removed bug Something isn't working labels Jul 3, 2024
@NobodyForNothing NobodyForNothing changed the title App throws exception when starting under Linux Desktop support Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants