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

Linux support (minor change needed) #3918

Closed
Tracked by #2515
christianfl opened this issue Apr 28, 2023 · 11 comments
Closed
Tracked by #2515

Linux support (minor change needed) #3918

christianfl opened this issue Apr 28, 2023 · 11 comments
Labels
✨ enhancement New feature or request linux ⭐ top issue Top issue.

Comments

@christianfl
Copy link

christianfl commented Apr 28, 2023

Problem

Hey! I noticed you added desktop support but so far tested only Mac OS: #3251 I tested building and running on Linux and it crashed with a database error.

Proposed solution

sqflite does not directly support other platforms than Android, iOS and Mac OS. However, there is the package sqflite_common_ffi from the same author for making it possible to support other desktop platforms. It was relatively easy to use that to make Smooth app running on Linux. These are the necessary steps:

  • Add dependency: flutter pub add sqflite_common_ffi
  • Open packages/smooth_app/lib/database/local_database.dart:
import 'package:sqflite_common_ffi/sqflite_ffi.dart' as ffi;

...

static Future<LocalDatabase> getLocalDatabase() async {
    ffi.sqfliteFfiInit(); // NEW
    databaseFactory = ffi.databaseFactoryFfi; // NEW

    // sql from there
    final 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();
    }
    final String databasePath = join(databasesRootPath, 'smoothie.db');
    final Database database = await databaseFactory.openDatabase(
      databasePath,
      options: OpenDatabaseOptions(
          version: 2, singleInstance: true, onUpgrade: _onUpgrade), // NEW
      // version: 2,
      // singleInstance: true,
      // onUpgrade: _onUpgrade,
    );

...

}
  • Run with: flutter run -d linux -t lib/entrypoints/android/main_fdroid.dart

I did not test wether that brakes support with Android / iOS so far!

Additional context

I would love to sometime use the Smooth app on the Librem 5 (Linux phone) It should definitely be possible as I already compiled some Flutter apps for that and they seem to run fine.

Edit: Hint – The packages libsqlite3 and libsqlite3-dev are required on the build machine and libsqlite3 on the running host.

image

Part of

@monsieurtanuki
Copy link
Contributor

Hi @christianfl!
Correct me if I'm wrong, but the only difference in your code is:

ffi.sqfliteFfiInit();
databaseFactory = ffi.databaseFactoryFfi;

That could probably be performed only once, at init time, and outside that class, right?

@christianfl
Copy link
Author

3 things in total @monsieurtanuki !

Easy to oversee is the final Database database = await databaseFactory.openDatabase() which additionally uses OpenDatabaseOptions a bit different from the original final Database database = await openDatabase().

ffi.sqfliteFfiInit(); can safely be called outside of that (e.g. in some of the main.dart files.

P.S.

  • Added the import statement in the original post
  • Added hint that linux packages are required in the original post

@monsieurtanuki
Copy link
Contributor

@christianfl Fair enough: I didn't notice the difference between your database = await databaseFactory.openDatabase( and the current database = await openDatabase( (basically with the same parameters).

We're not going to spoil the current implementation: we're going to use abstraction instead.
Something like a DatabaseOpener interface with a unique Database openDatabase(String path, int version, onUpgrade) method. And LinuxDatabaseOpener and StandardDatabaseOpener implementations.

Then a new parameter in main.dart's launchSmoothApp and in LocalDatabase getLocalDatabase(DatabaseOpener).

Does that make sense?

@teolemon teolemon added the linux label Apr 29, 2023
@christianfl
Copy link
Author

Does that make sense?

I thought about that and to my mind: Yes! I think the FFI approach is a bit "fiddly" at the moment and also relies on packages installed on the host system. It would be a good idea to only activate that with another parameter for launchSmoothApp.

So that would perhaps be used with a new linux entrypoint? This way it would also be easy to add other platforms with FFI later without using statements like:

if (Platform.isLinux || Platform.isWindows) {
  // fiddly FFI code here
}

@monsieurtanuki
Copy link
Contributor

@christianfl Indeed.
We need to finish the Fdroid install process first.
The point here is not to import irrelevant packages (e.g. for Fdroid: no MLKit).
Once we have no problem creating new entry points with specific packages that do not impact at all the other versions, we'll be 100% ready for a new linux entry point.

@teolemon
Copy link
Member

Low priority ideas

  • Also related an nice would be to automate packaging for popular versions of Linux, and potentially distribution.
  • For desktop, that could be an occasion to improve tablet support

@christianfl
Copy link
Author

  • Also related an nice would be to automate packaging for popular versions of Linux, and potentially distribution.

I also had in mind to open an issue for distributing on Flathub later but didn't want to overwhelm you for now...

@12people
Copy link

I could potentially help with the Flathub distribution once this is settled. I have several Flutter apps on Flathub myself. So far, I've always released each version manually, but I'm working on automating releases via Github Actions.

@teolemon
Copy link
Member

that's great @12people 👍
We could cannibalize some of that which seems to build and publish to flathub: https://github.com/rustdesk/rustdesk/blob/master/.github/workflows/flutter-build.yml ?
Feel free to open a separate issue for the packaging

@teolemon
Copy link
Member

@g123k

@g123k
Copy link
Collaborator

g123k commented Jun 22, 2024

Implemented in #5431

@g123k g123k closed this as completed Jun 22, 2024
@github-project-automation github-project-automation bot moved this from 💬 To discuss and validate to 🎊 Done in 🤳🥫 The Open Food Facts mobile app (Android & iOS) Jun 22, 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 linux ⭐ top issue Top issue.
Development

No branches or pull requests

5 participants