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

system_alert_window 封面
插件详情v2.0.11

system_alert_window

一个 Flutter 插件,可在所有其他应用之上显示类似 Truecaller 的覆盖窗口,并支持回调事件。

AndroidiOS
近 30 天下载
7950
喜欢数
253
Pub 分数
150

安装插件

flutter pub add system_alert_window

插件介绍

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

一个 Flutter 插件,可在 Android 和 iOS 上显示持久的、系统级别的覆盖窗口,类似于 Truecaller 的警报界面。它位于所有其他应用之上,并支持用户交互的回调事件。专为高可见性通知或紧急警报设计,可无缝集成原生系统权限。该插件适用于需要立即引起用户注意而无需依赖标准推送通知的应用程序。

适合场景

  • 显示紧急警报
  • 创建始终置顶的通知窗口
  • 实现呼叫阻止接口
  • 启用实时状态叠加
  • 提供系统级交互提示

主要特点

  • 系统叠加支持
  • 跨平台(Android 和 iOS)
  • 回调事件处理
  • 在其他应用之上的持久显示
  • 与系统权限设置的集成

适合对象

  • 安全和隐私应用
  • 呼叫管理工具
  • 实时监控工具
  • 紧急警报系统
  • 需要高优先级用户交互的应用

使用建议

  • 需要 Android 系统权限
  • 由于平台限制,iOS 功能有限
  • 可能被安全应用程序标记
  • 用户必须手动启用叠加权限
  • 潜在的电池和性能影响

原始 README

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

system_alert_window

Pub

A flutter plugin to show Truecaller like overlay window, over all other apps along with callback events. Android Go or Android 11 & above, this plugin shows notification bubble, in other android versions, it shows an overlay window.

Android

Demo
1. Clip of example app and 2. Working of button click in the background

      

Manifest
  //Permissions
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE " />
  <uses-permission android:name="android.permission.WAKE_LOCK" />


      <application
          //Linking the previously added application class
          android:name=".Application"
          android:label="system_alert_window_example"
          android:icon="@mipmap/ic_launcher">
Android 10 & below, Android GO (API 27)

Uses 'draw on top' permission and displays it as a overlay window

Android 11 & above

With SystemWindowPrefMode.OVERLAY, system alert windows uses 'overlay functionality' wherever it's supported. In that mode, it will show as bubbles if the 'display over other apps' is not supported. With SystemWindowPrefMode.DEFAULT/SystemWindowPrefMode.BUBBLE, User has to allow 'All conversations can bubble' in the notification settings of the app. Uses Android Bubble APIs to show the overlay window inside a notification bubble.

Edge-to-edge content and window insets are handled automatically inside the bubble container — wrap your overlay widget with SafeArea to avoid content being obscured by system bars.

Android GO (API 29)

User has to manually enable bubbles from the developer options. Uses Android Bubble APIs to show the overlay window inside a notification bubble.

IOS

Displays as a notification in the notification center [Help Needed]

Example

Show Overlay
Request overlay permission
  await SystemAlertWindow.requestPermissions;
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"))
  ));
}


 //Open overLay content

//  - Optional arguments:
/// `gravity` Position of the window and default is [SystemWindowGravity.CENTER]
/// `width` Width of the window and default is [Constants.MATCH_PARENT]
/// `height` Height of the window and default is [Constants.WRAP_CONTENT]
/// `notificationTitle` Notification title, applicable in case of bubble
/// `notificationBody` Notification body, applicable in case of bubble
/// `prefMode` Preference for the system window. Default is [SystemWindowPrefMode.DEFAULT]
/// `layoutParamFlags` List of List of WindowManager.LayoutParams. This is not applicable for bubbles.
await SystemAlertWindow.showSystemWindow();

/// update the overlay flag while the overlay in action
///   - Optional arguments:
/// `gravity` Position of the window and default is [SystemWindowGravity.CENTER]
/// `width` Width of the window and default is [Constants.MATCH_PARENT]
/// `height` Height of the window and default is [Constants.WRAP_CONTENT]
/// `notificationTitle` Notification title, applicable in case of bubble
/// `notificationBody` Notification body, applicable in case of bubble
/// `prefMode` Preference for the system window. Default is [SystemWindowPrefMode.DEFAULT]
/// `layoutParamFlags` List of List of WindowManager.LayoutParams. This is not applicable for bubbles.
await FlutterOverlayWindow.updateSystemWindow();

 // closes overlay if open
await SystemAlertWindow.closeSystemWindow();

 // broadcast data to overlay app from main app
await SystemAlertWindow.sendMessageToOverlay("Hello from the other side");

 //streams message from main app to overlay.
SystemAlertWindow.overlayListener.listen((event) {
log("Current Event: $event");
});




Isolate communication
Use this snippet, if you want the callbacks on your main thread
Create an isolate_manager.dart
import 'dart:isolate';

import 'dart:ui';

class IsolateManager{

  static const FOREGROUND_PORT_NAME = "foreground_port";

  static SendPort lookupPortByName() {
    return IsolateNameServer.lookupPortByName(FOREGROUND_PORT_NAME);
  }

  static bool registerPortWithName(SendPort port) {
    assert(port != null, "'port' cannot be null.");
    removePortNameMapping(FOREGROUND_PORT_NAME);
    return IsolateNameServer.registerPortWithName(port, FOREGROUND_PORT_NAME);
  }

  static bool removePortNameMapping(String name) {
    assert(name != null, "'name' cannot be null.");
    return IsolateNameServer.removePortNameMapping(name);
  }

}
While initializing system alert window in your code
    await SystemAlertWindow.checkPermissions;
    ReceivePort _port = ReceivePort();
    IsolateManager.registerPortWithName(_port.sendPort);
    _port.listen((message) {
          log("message from OVERLAY: $message");
          print("Do what ever you want here. This is inside your application scope");
    });
Use this to send data to isolate mentioned above
void callBackFunction(String tag) {
  print("Got tag " + tag);
  SendPort port = IsolateManager.lookupPortByName();
  port.send(tag);
}

所属分类

源码仓库

使用此插件的项目

暂无相关数据。