Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to build android widgets in flutter?

The fact that Flutter heavily uses the word widget makes it difficult to find documentation on this topic. On Android (I believe this isn't possible on iOS), we can add widgets on our home dashboard, allowing us to see app-related information or to trigger one-click actions without needing to open the app in question.

Is it possible to build such "widgets" in Dart & Flutter? Or should I do that in java and somehow plug it with my flutter app?

Can you share an example of a resource containing one?

EDIT: I have no android development experience, but it sounds like using a drawable canvas might do the trick. I could find some canvas flutter code, but I can't connect the dots yet.

EDIT 2: From this Github issue, it looks like writing android home widgets in flutter is a no go since Flutter has its own rendering engine. I'm keen on learning kotlin to get this done, but if someone knew of nice tutorials to help me with that, that would be immensely helpful.

like image 539
Adrien Lemaire Avatar asked Nov 27 '17 05:11

Adrien Lemaire


People also ask

Can you make widgets with Flutter?

If you want to go really low level, it's also possible to make widgets the same way that the Flutter framework does it: by using RenderObject s. The best way to learn about this is to explore the Flutter source code of a widget similar to the one you want to make.

Can we develop Android app using Flutter?

Flutter is a recently launched SDK by Google, allowing developers to create applications for iOS and Android by using a single code-base. Unlike other popular solutions, rather than calling Flutter a framework, it is a complete SDK that comes with everything that you will need to build cross-platform applications.

Is Flutter enough for Android development?

Flutter provides widgets that perfectly follow Android's Material Design and Apple's Cupertino looks. The UI customization that usually takes the longest to finish in cross-platform development requires a minimum amount of time with Flutter.

How do I create a widget on Flutter app?

Create a basic Flutter Project and keep the starter code of the counter app as it is. Add package home_widget in your pubspec. yaml. It will help in sending data, retrieving data, and updating the widgets from the flutter itself.


1 Answers

As the OP mentioned in an edit, this isn't currently possible because Flutter uses a custom rendering engine.

Widgets are quite limited in what they can render; the documentation explains that only certain layouts may be used. You could theoretically use Flutter's software renderer to render to an image in a seperate instance from the main one and display that, but that would be very technical, likely not very performant, and not straightforward at all!

Here is a quite detailed tutorial for widgets that guides you through creating a few examples although in Java. The same logic applies with just a few syntactical changes for Kotlin as the classes are pretty much interchangeable. However, realistically, most of the work is in the layout with some wiring in android; if you're already familiar with Android & Java, keep in mind that Kotlin does add a bit to your app size (The Kotlin runtime adds about 7,000 methods and ~1MB to your debug APK from the kotlin on android FAQ) and since most of your logic should be in flutter you probably won't have all that much Kotlin/Java code if this is all you're using it for (although if you're new to both Java & Kotlin, Kotlin is arguably more friendly in some ways).

Also, to be able to communicate between your flutter app and the java/kotlin backend, you'll need to use platform channels as described in the flutter documentation.

like image 174
rmtmckenzie Avatar answered Sep 22 '22 02:09

rmtmckenzie