是否可以在flutter中构建android小部件?

编程入门 行业动态 更新时间:2024-10-27 13:20:54
本文介绍了是否可以在flutter中构建android小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Flutter大量使用widget这个事实使得很难找到有关此主题的文档。 在Android上(我认为这在iOS上是不可能的),我们可以在家庭仪表板上添加小部件,从而使我们能够查看与应用程序有关的信息或触发一键式操作,而无需打开有问题的应用程序。

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.

是否有可能在Dart&中建立这样的部件?扑?还是我应该在Java中执行此操作,然后以某种方式将其插入我的flutter应用程序中?

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?

编辑:我没有android开发经验,但听起来像是使用可绘制的画布可以解决问题。 我可以找到一些画布抖动代码

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.

编辑2:来自此Github问题,由于Flutter具有自己的渲染引擎,因此用flutter编写android home小部件似乎是不行的。我热衷于学习 kotlin 来完成这项工作,但是如果有人知道很好

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.

推荐答案

正如编辑中提到的OP那样,这不是很有帮助。由于Flutter使用了自定义渲染引擎,因此目前可以使用。

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

小部件可呈现的内容非常有限; 文档解释说,只能使用某些布局。从理论上讲,您可以使用Flutter的软件渲染器在与主实例不同的实例中渲染图像并进行显示,但这将是非常技术性的,可能不是很高效,并且根本不简单!

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!

此处是有关小部件的非常详细的教程指导您创建一些示例(尽管使用Java)。相同的逻辑仅适用于Kotlin的一些语法更改,因为这些类几乎可以互换。但是,实际上,大多数工作是在android中进行一些布线的布局中。如果您已经熟悉Android& Java,请记住,Kotlin确实会增加您的应用程序大小( Kotlin运行时会从 android FAQ上的kotlin ),由于您的大多数逻辑都应该扑朔迷离,所以您可能一无所获很多Kotlin / Java代码(如果这就是您要使用的全部代码)(尽管您既是Java&Kotlin的新手,也可以说Kotlin在某些方面更友好)。

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).

此外,为了能够在Flutter应用程序与java / kotlin后端之间进行通信,您需要使用 Flutter文档。

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.

更多推荐

是否可以在flutter中构建android小部件?

本文发布于:2023-07-20 17:55:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:部件   flutter   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!