[英]How to have widgets outside the app using flutter and kotlin?
I need a way to make a button or a container that can still be visible even when I close the app like so:我需要一种方法来制作一个按钮或容器,即使我像这样关闭应用程序仍然可以看到它:
.
. But this is just simply impossible in flutter.
但这在颤振中根本不可能。 So what I've been doing is making a platform channel on my app and trying to make the container and button with native components.
所以我一直在做的是在我的应用程序上创建一个平台频道,并尝试使用本机组件制作容器和按钮。 But I've been using kotlin and do not know much about this programming language.
但是我一直在使用 kotlin 并且对这种编程语言了解不多。 Is there a way for my code to be able to make such widgets?(I would thank you so much if you could edit my full code.)
有没有办法让我的代码能够制作这样的小部件?(如果你能编辑我的完整代码,我将非常感谢你。)
Full Code:完整代码:
Flutter:扑:
class FloatingContainer extends StatelessWidget {
static const platform = const MethodChannel('flutter.App.com.channel');
@override
Widget build(BuildContext context) {
return Container ();
}
Future<Null> _showNativeView() async {}
}
Kotlin:科特林:
package com.example.swipe
import android.os.Bundle
import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugin.common.MethodChannel
class MainActivity() : FlutterActivity() {
private val CHANNEL = "flutter.App.com.channel"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->
}
}
}
This is known as a Draw Over Other apps.这称为绘制其他应用程序。
This feature is not available in the iOS probably that's the reason flutter doesn't has this feature or official package for it.此功能在 iOS 中不可用,这可能是 Flutter 没有此功能或官方软件包的原因。
But to achieve this feature in your application you can write up some PlatformChannels
.但是要在您的应用程序中实现此功能,您可以编写一些
PlatformChannels
。
This permission allow you to draw on top of everything. 此权限允许您在所有内容之上绘图。
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications.
允许应用程序使用 TYPE_SYSTEM_ALERT 类型打开窗口,显示在所有其他应用程序的顶部。 Very few applications should use this permission;
很少有应用程序应该使用此权限; these windows are intended for system-level interaction with the user.
这些窗口用于与用户进行系统级交互。
Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"
常量值:“android.permission.SYSTEM_ALERT_WINDOW”
This code can also help you out to achieve this.此代码也可以帮助您实现这一目标。
You can also check out springy-heads library by Flipkart-Incubator too.您也可以通过 Flipkart-Incubator 查看springy-heads库。
您好,在这种情况下,您正在搜索PlatformChannels您可以在此处查看文档: https : //flutter.dev/docs/development/platform-integration/platform-channels或者如果您希望我在我的网站上有一篇关于此的小帖子: http://fjbatresv.com/flutter-tambien-habla-nativo/ (在帖子顶部选择您的语言。)
Apart from restriction that it won't work on IOS, there is a plugin in flutter called System Alert Window , which does the same除了不能在 IOS 上运行的限制外,flutter 中还有一个名为System Alert Window的插件,它的作用相同
It shows Truecaller like overlay window, over all other apps along with callback events它在所有其他应用程序以及回调事件上显示 Truecaller 之类的覆盖窗口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.