搜尋套件、儲存庫與 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);
}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。