Flutter in Ubuntu

127 views
Skip to first unread message

robert...@canonical.com

unread,
Sep 17, 2019, 6:08:05 AM9/17/19
to Desktop Embedding for Flutter
Hi,

I'm a member of the Ubuntu desktop team and we're currently investigating the use of Flutter for desktop apps. I thought I'd talk about some of the things we're looking at to see if anyone else is working on these and can help with some of the issues we've been encountering.

- D-Bus support

To integrate with the desktop apps are going to need some sort of D-Bus support. This would probably be done with a native Dart package. We considered wrapping existing libraries but feel that for debugging reasons a native implementation will probably work better.

- Implement Unix Domain Sockets

To support D-Bus and other local services Dart needs support for Unix Domain Sockets [1]. I've made a simple C Dart extension that wraps the appropriate syscalls (socket/connect/read/write) and then has a Dart class that uses these. Ideally this would be proposed into Dart as a number of other people seem to want this. I've come up against two issues:

1. It's not clear to me how to make this code asynchronous. Should I:
 - Be able to register the file descriptor somewhere in Dart and respond in callbacks? I haven't found any code that seems to do this.
 - Use a Dart isolate to wrap the extension. This seems like code that would be better to avoid if I could do the above.
I've been looking at the TCP socket implementation in the Dart VM and haven't worked out the method used there to make it asynchronous. Anyone know?

2. Extension don't seem to load in the Dart that comes with the Flutter SDK [2]. I've tried both the downloaded version and built from the git branch with no luck. If I just use the Dart SDK / git branch they work fine. Is this a bug or are extensions not supposed to work with Flutter?

- Distributing Flutter based apps as snaps [3].

We've just started on this and working out how to make this work easily.

Thanks,
--Robert Ancell


Geert-Johan Riemer

unread,
Sep 17, 2019, 7:42:45 AM9/17/19
to robert...@canonical.com, Desktop Embedding for Flutter
Hi,

Just a bit of shameless project promotion here. I hope you will find this useful.

I'm one of the developers of an alternative Flutter Embedder for Desktops; https://github.com/go-flutter-desktop/go-flutter
This is not an official Flutter project; it is not maintained by the Flutter team. The project expands on the Flutter Engine and its published embedder headers.

go-flutter exposes the Flutter engine and plugin structure as Go packages, which can be used to create desktop apps (linux, macos, windows) and go-flutter plugins.
I think it is possible to expose D-Bus through the Flutter plugin system. Doing this in Go could benefit both Darwin and Linux systems. (https://github.com/godbus/dbus)
However, as you say, a native implementation in Dart also has its benefits. Have you looked at Dart FFI?

The team behind go-flutter has also created hover, a tool that helps building and distributing go-flutter apps. It has recently gained basic support for packaging (snap and deb). https://github.com/go-flutter-desktop/hover#packaging
Cross-compiling is about to land soon.

Kind regards,
Geert-Johan Riemer


--
You received this message because you are subscribed to the Google Groups "Desktop Embedding for Flutter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-desktop-embe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-desktop-embedding-dev/b019cd41-133c-4f8f-8607-7b3fd96e21ee%40googlegroups.com.

Stuart Morgan

unread,
Sep 17, 2019, 12:42:12 PM9/17/19
to robert...@canonical.com, Desktop Embedding for Flutter
On Tue, Sep 17, 2019 at 3:08 AM <robert...@canonical.com> wrote:
I'm a member of the Ubuntu desktop team and we're currently investigating the use of Flutter for desktop apps.

Great! I'm happy to answer questions as best I can. Since Linux is still in the early stages sometimes we may not always have all the answers, but even then getting feedback on what people are trying to do and what is and isn't working is very useful.
 
- D-Bus support

To integrate with the desktop apps are going to need some sort of D-Bus support. This would probably be done with a native Dart package. We considered wrapping existing libraries but feel that for debugging reasons a native implementation will probably work better.

As far as I know nobody has done work in this area. I don't have specific guidance on where the best place to draw the line between Dart and C would be, but I would expect that it's largely a matter of personal preference.
 
- Implement Unix Domain Sockets

To support D-Bus and other local services Dart needs support for Unix Domain Sockets [1]. I've made a simple C Dart extension that wraps the appropriate syscalls (socket/connect/read/write) and then has a Dart class that uses these. Ideally this would be proposed into Dart as a number of other people seem to want this. I've come up against two issues:

1. It's not clear to me how to make this code asynchronous. Should I:
 - Be able to register the file descriptor somewhere in Dart and respond in callbacks? I haven't found any code that seems to do this.
 - Use a Dart isolate to wrap the extension. This seems like code that would be better to avoid if I could do the above.
I've been looking at the TCP socket implementation in the Dart VM and haven't worked out the method used there to make it asynchronous. Anyone know?

For lower-level Dart questions like this, your best resource is probably one of the Dart lists or communities: https://dart.dev/community. Since list is narrowly scoped to desktop, many of the people who would be best able to answer a Dart question like this are probably not on this list.

2. Extension don't seem to load in the Dart that comes with the Flutter SDK [2]. I've tried both the downloaded version and built from the git branch with no luck. If I just use the Dart SDK / git branch they work fine. Is this a bug or are extensions not supposed to work with Flutter?

Flutter indeed does not support Dart's native extensions. However, Flutter support for dart:ffi just launched as a preview, which will let you accomplish much the same thing. See https://medium.com/dartlang/announcing-dart-2-5-super-charged-development-328822024970 for an overview and links to more details.

The more established way of doing this would be with Flutter's platform channels:
We have preliminary support for them on Linux (the APIs are not finalized; feedback welcome if you decide to go that route!), and there are a few Linux plugins in the FDE repository that show examples of using them:
color_panel does asynchronous callbacks from C++ to Dart, for instance.
 
- Distributing Flutter based apps as snaps [3].

We've just started on this and working out how to make this work easily.

I'm not sure if anyone in the community has started looking at this; it's not within the scope of things we've investigated within the project itself. The current state on Linux is that when you build, it creates a self-contained (not including system-level library dependencies) folder, including the executable, the Flutter library, any plugin libraries, and the Flutter resources. If you have questions about the details of that, and/or feedback on ways it could be structured differently to make packaging easier (that structure is not something we've iterated on at all), please let us know!

-Stuart

Kevin Segaud

unread,
Sep 18, 2019, 3:29:03 AM9/18/19
to Desktop Embedding for Flutter
Hi,
We have gain some experience at Rushio Consulting (https://rushio-consulting.fr) about ffi if you need support don't hesitate to contact us.

Unix socket should be relatively straightforward to wrap with ffi.

We have started to wrap libsodium with ffi without real difficulty, source are here https://github.com/rushio-consulting/libsodium.dart

Robert Ancell

unread,
Sep 18, 2019, 5:13:02 AM9/18/19
to Geert-Johan Riemer, Desktop Embedding for Flutter
Thank you for the information! This is an interesting option, as we use Go a lot within Canonical.

My current focus is on the core Flutter desktop support, on the assumption that this becomes non-experimental in the future. So I'll first look at how we can make that experience work great in Ubuntu.

--Robert

Robert Ancell

unread,
Sep 18, 2019, 5:20:09 AM9/18/19
to Stuart Morgan, Desktop Embedding for Flutter
On Tue, Sep 17, 2019 at 6:42 PM Stuart Morgan <stuart...@google.com> wrote:
On Tue, Sep 17, 2019 at 3:08 AM <robert...@canonical.com> wrote:

2. Extension don't seem to load in the Dart that comes with the Flutter SDK [2]. I've tried both the downloaded version and built from the git branch with no luck. If I just use the Dart SDK / git branch they work fine. Is this a bug or are extensions not supposed to work with Flutter?

Flutter indeed does not support Dart's native extensions. However, Flutter support for dart:ffi just launched as a preview, which will let you accomplish much the same thing. See https://medium.com/dartlang/announcing-dart-2-5-super-charged-development-328822024970 for an overview and links to more details.

The more established way of doing this would be with Flutter's platform channels:
We have preliminary support for them on Linux (the APIs are not finalized; feedback welcome if you decide to go that route!), and there are a few Linux plugins in the FDE repository that show examples of using them:
color_panel does asynchronous callbacks from C++ to Dart, for instance.

Thank you, this is *exactly* the information I was looking for. We'll push ahead with FFI for a first implementation and look at potentially getting this into a platform channel or Dart as a core feature if appropriate in the future.

 
- Distributing Flutter based apps as snaps [3].

We've just started on this and working out how to make this work easily.

I'm not sure if anyone in the community has started looking at this; it's not within the scope of things we've investigated within the project itself. The current state on Linux is that when you build, it creates a self-contained (not including system-level library dependencies) folder, including the executable, the Flutter library, any plugin libraries, and the Flutter resources. If you have questions about the details of that, and/or feedback on ways it could be structured differently to make packaging easier (that structure is not something we've iterated on at all), please let us know!

I'm sure we'll be back later with questions and feedback :)
Reply all
Reply to author
Forward
0 new messages