搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.0

flutter_overlay_apps

Android 插件,用於在其他應用程式之上顯示 Flutter 小部件

Android
近 30 天下載
58
喜歡數
71
Pub 分數
160

安裝套件

flutter pub add flutter_overlay_apps

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,可讓 Flutter 小部件顯示為其他 Android 應用程式之上的覆蓋層。它允許開發者建立持續的 UI 元素,例如浮動按鈕、通知或即時資料顯示,這些元素在應用程式切換時仍保持可見。該插件與 Android 系統覆蓋權限整合,並在 Flutter 與原生 Android 覆蓋功能之間提供橋接。專為 Android 設計,支援自訂定位與對覆蓋內容的互動。

適用情境

  • 遊戲應用中的浮動控制項
  • 即時數據監控疊加
  • 持久的通知橫幅
  • 應用內幫助工具
  • 用於生產力應用的疊加小部件

主要特色

  • 僅限 Android 的疊加支援
  • 系統權限處理
  • 可自定的小部件位置
  • 互動式疊加元素
  • 與 Flutter UI 的無縫整合

適合對象

  • 針對 Android 叠加功能的開發者
  • 需要持久化螢幕UI的應用程式
  • 需要跨應用可見性的工具
  • 遊戲或生產力增強應用
  • 在應用切換期間必須保持可見的 UI

使用建議

  • 需要 Android 系統覆蓋層權限
  • 僅限 Android 平台
  • 可能受到設備製造商的限制
  • 使用者必須手動啟用覆蓋層權限
  • 複雜覆蓋層可能帶來的效能影響

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_overlay_apps

Android plugin for displaying flutter app over other apps

Usage

Add dependency to pubspec.yaml file

Android

You'll need to add the SYSTEM_ALERT_WINDOW permission and OverlayService to your Android Manifest.

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <application>
        ...
        <service
           android:name="com.phan_tech.flutter_overlay_apps.OverlayService"
           android:exported="false" />
    </application>
Entry point

Inside main.dart create an entry point for your Overlay widget; NOTE: MaterialApp is required

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

To open an overlay, call FlutterOverlayApps.showOverlay(). Default height & width is fill screen

FlutterOverlayApps.showOverlay(height: 300, width: 400, alignment: OverlayAlignment.center);

To close the overlay widget call

FlutterOverlayApps.closeOverlay();

To send data to and from Overlay widget, call

FlutterOverlayApps.sendDataToAndFromOverlay(<data>);

For listening to broadcasted data, stream the messages by calling

FlutterOverlayApps.overlayListener().listen((data) {
    print(data);
});
Code Example
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_overlay_apps/flutter_overlay_apps.dart';

void main() {
  runApp(const MyApp());
}

// overlay entry point
@pragma("vm:entry-point")
void showOverlay() {
  runApp(const MaterialApp(
    debugShowCheckedModeBanner: false,
    home: MyOverlaContent()
  ));
}


class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () async {

              // Open overlay
              await FlutterOverlayApps.showOverlay(height: 300, width: 400, alignment: OverlayAlignment.center);

              // send data to ovelay
              await Future.delayed(const Duration(seconds: 2));
              FlutterOverlayApps.sendDataToAndFromOverlay("Hello from main app");
            }, 
            child: const Text("showOverlay")
          ),
        ),
      ),
    );
  }
}



class MyOverlaContent extends StatefulWidget {
  const MyOverlaContent({ Key? key }) : super(key: key);

  @override
  State<MyOverlaContent> createState() => _MyOverlaContentState();
}

class _MyOverlaContentState extends State<MyOverlaContent> {
  String _dataFromApp = "Hey send data";

  @override
  void initState() {
    super.initState();

    // lisent for any data from the main app
    FlutterOverlayApps.overlayListener().listen((event) {
      setState(() {
        _dataFromApp = event.toString();
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: InkWell(
        onTap: (){
          // close overlay
          FlutterOverlayApps.closeOverlay();
        },
        child: Card(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
          child: Center(child: Text(_dataFromApp, style: const TextStyle(color: Colors.red),)),
        ),
      ),
    );
  }
}

Android back button

The back navigation button on android will close the overlay app. To prevent this, set closeOnBackButton to false. Example;

await FlutterOverlayApps.showOverlay(
  height: 300,
  closeOnBackButton: false,
  alignment: OverlayAlignment.center);

When closeOnBackButton is set to false, an action will be sent via the stream controller. You can get the action like the example below;

var overlayStreamController = FlutterOverlayApps.overlayListener();

overlayStreamController.stream.listen((event) {
  if(event['method'] == 'backButton'){
    // handle back button 
    if(mounted && Navigator.of(context).canPop()){
      Navigator.of(context).pop();
    }
  }
})

Support the plugin Buy Me A Coffee

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。