패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.0

flutter_overlay_apps

다른 앱 위에 플러터 위젯을 표시하기 위한 안드로이드 플러그인

Android
30일 다운로드
58
좋아요
71
Pub 점수
160

패키지 설치

flutter pub add flutter_overlay_apps

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

다른 Android 애플리케이션 위에 Flutter 위젯을 오버레이로 표시할 수 있는 Flutter 플러그인입니다. 개발자는 앱 전환 중에도 항상 보이는 지속적인 UI 요소(예: 플로팅 버튼, 알림, 실시간 데이터 표시)를 만들 수 있습니다. 이 플러그인은 Android 시스템 오버레이 권한과 통합되며, Flutter와 네이티브 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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.