简体   繁体   English

如何使用 flutter 和 kotlin 在应用程序外拥有小部件?

[英]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:我需要一种方法来制作一个按钮或容器,即使我像这样关闭应用程序仍然可以看到它: https://i.stack.imgur.com/GTpOim.jpg . . 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.

相关问题 如何使用kotlin在android中初始化小部件 - How to initialize widgets in android using kotlin 如何使用颤振构建小部件? - how can I build Widgets using flutter? 在 kotlin 多平台应用程序中使用颤振模块 - Using flutter module in kotlin multiplatform app 如何在 flutter 应用程序之外显示模态 - how to show a modal outside a flutter app 如何在Flutter中使用动态大小的小部件设置BackdropFilter - How to set a BackdropFilter using dynamic-sized widgets in Flutter Flutter:如何在使用 Sliver 小部件时在滚动时隐藏 BottomAppBar? - Flutter: How to hide BottomAppBar on scroll when using Sliver widgets? 当设备大小更改时,如何在Android应用中的Flutter View发行模式下重建Flutter小部件? - How to rebuild Flutter widgets when device size changes, in release mode for Flutter View in Android app? Kotlin 文件在 Flutter 应用程序中无法识别 - Kotlin files not recognized in Flutter app 如何使用 Kotlin 在 Activity 类之外的 Android 中获取文件 - How to get file in Android outside Activity class using Kotlin 如何返回上一个活动? Kotlin(使用操作栏外的按钮) - How to GoBack to the previous Activity ? Kotlin ( using a button outside the action bar)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM