搜索插件、代码仓与 APP 分类

flutter_overlay_window 封面
插件详情v1.0.2

flutter_overlay_window

用于在屏幕上显示您的 Flutter 应用程序覆盖其他应用程序的 Flutter 插件

Android
近 30 天下载
1.6万
喜欢数
532
Pub 分数
160

安装插件

flutter pub add flutter_overlay_window

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,使应用程序能够在 Android 上的其他应用之上显示内容,例如浮动窗口或叠加层。它允许开发者创建在不同应用上下文中保持可见的持久性 UI 元素,非常适合用于聊天头、媒体控制或实时通知等工具。该插件与 Android 系统的叠加权限集成,并提供简单的 API 来管理叠加窗口的位置、可见性和交互。对于需要持续用户关注但又不希望完全中断屏幕的应用尤其有用。

适合场景

  • 浮动聊天头像
  • 实时通知
  • 媒体控制叠加层
  • 持久化 UI 小部件
  • 屏幕录制助手

主要特点

  • 仅支持 Android
  • 系统叠加权限处理
  • 可自定义叠加层大小和位置
  • 简单的 API 用于显示/隐藏
  • 后台执行兼容性

适合对象

  • 需要持久化屏幕元素的应用程序
  • 开发交互式叠加层的开发者
  • 需要最少用户交互的工具
  • 面向 Android 的 Flutter 项目
  • 无障碍或实用程序应用

使用建议

  • 需要 Android 系统叠加层权限
  • 仅限 Android 平台
  • 可能受设备制造商限制
  • 用户必须手动启用叠加层权限
  • 潜在的电池和性能影响

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

auto_route_logo

MIT License stars pub version

Buy Me A Coffee

Flutter plugin for displaying your Flutter app over other apps on the screen


Preview

TrueCaller overlay example click-through overlay example Messanger chat-head example

Installation

Add package to your pubspec:

dependencies:
  flutter_overlay_window: any # or the latest version on Pub
Android

You'll need to add the SYSTEM_ALERT_WINDOW permission and OverlayService to your Android Manifest. Replace explanation_for_special_use with your custom explanation.

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

    <application>
        ...
        <service android:name="flutter.overlay.window.flutter_overlay_window.OverlayService" 
            android:exported="false"
            android:foregroundServiceType="specialUse">
            <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
                android:value="explanation_for_special_use"/>
        </service>
    </application>
Entry point

Inside main.dart create an entry point for your Overlay widget;


// overlay entry point
@pragma("vm:entry-point")
void overlayMain() {
  runApp(const MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Material(child: Text("My overlay"))
  ));
}

USAGE
 /// check if overlay permission is granted
 final bool status = await FlutterOverlayWindow.isPermissionGranted();

 /// request overlay permission
 /// it will open the overlay settings page and return `true` once the permission granted.
 final bool status = await FlutterOverlayWindow.requestPermission();

  /// Open overLay content
  ///
  /// - Optional arguments:
  ///
  /// `height` the overlay height and default is [WindowSize.fullCover]
  ///
  /// `width` the overlay width and default is [WindowSize.matchParent]
  ///
  /// `alignment` the alignment postion on screen and default is [OverlayAlignment.center]
  ///
  /// `visibilitySecret` the detail displayed in notifications on the lock screen and default is [NotificationVisibility.visibilitySecret]
  ///
  /// `OverlayFlag` the overlay flag and default is [OverlayFlag.defaultFlag]
  ///
  /// `overlayTitle` the notification message and default is "overlay activated"
  ///
  /// `overlayContent` the notification message
  ///
  /// `enableDrag` to enable/disable dragging the overlay over the screen and default is "false"
  ///
  /// `positionGravity` the overlay postion after drag and default is [PositionGravity.none]
  ///
  /// `startPosition` the overlay start position and default is null
 await FlutterOverlayWindow.showOverlay();

 /// closes overlay if open
 await FlutterOverlayWindow.closeOverlay();

 /// broadcast data to and from overlay app
 await FlutterOverlayWindow.shareData("Hello from the other side");

 /// streams message shared between overlay and main app
  FlutterOverlayWindow.overlayListener.listen((event) {
      log("Current Event: $event");
    });

 /// use [OverlayFlag.focusPointer] when you want to use fields that show keyboards
 await FlutterOverlayWindow.showOverlay(flag: OverlayFlag.focusPointer);


 /// update the overlay flag while the overlay in action
 await FlutterOverlayWindow.updateFlag(OverlayFlag.defaultFlag);

 /// Update the overlay size in the screen
 await FlutterOverlayWindow.resizeOverlay(80, 120);

 /// Update the overlay position in the screen
 ///
 /// `position` the new position of the overlay
 ///
 /// `return` true if the position updated successfully
 await FlutterOverlayWindow.moveOverlay(OverlayPosition(0, 156))

 /// Get the current overlay position
 ///
 /// `return` the current overlay position
 await FlutterOverlayWindow.getOverlayPosition()


enum OverlayFlag {
  /// Window flag: this window can never receive touch events.
  /// Usefull if you want to display click-through overlay
  clickThrough,

  /// Window flag: this window won't ever get key input focus
  /// so the user can not send key or other button events to it.
  defaultFlag,

  /// Window flag: allow any pointer events outside of the window to be sent to the windows behind it.
  /// Usefull when you want to use fields that show keyboards.
  focusPointer,
}


  /// Type of dragging behavior for the overlay.
  enum PositionGravity {
    /// The `PositionGravity.none` will allow the overlay to postioned anywhere on the screen.
    none,

    /// The `PositionGravity.right` will allow the overlay to stick on the right side of the screen.
    right,

    /// The `PositionGravity.left` will allow the overlay to stick on the left side of the screen.
    left,

    /// The `PositionGravity.auto` will allow the overlay to stick either on the left or right side of the screen depending on the overlay position.
    auto,
  }


所属分类

源码仓库

使用此插件的项目