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

floating 封面
套件詳情v6.0.0

floating

適用於 Flutter 的畫中畫模式管理。僅適用於 Android。

Android
近 30 天下載
2.3萬
喜歡數
270
Pub 分數
160

安裝套件

flutter pub add floating

套件介紹

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

浮動套件為Flutter應用程式中的畫中畫(PiP)模式管理提供支援,專用於Android。它允許開發者將媒體播放無縫轉換為可移動和可調整大小的小型浮動視窗,同時使用者可與其他應用程式互動。這對於需要在背景持續播放的影片或音訊內容特別有用。該套件直接整合Android的PiP API,提供一個直覺的介面來控制PiP行為。它支援需要持續播放但不需要完全聚焦應用程式的影片和音訊使用情境。

適用情境

  • 背景影片播放
  • 畫中畫模式下的音頻串流
  • 需要連續播放的媒體應用
  • Android 上的多任務處理支援
  • 影片通話中的最小化視圖

主要特色

  • 僅限 Android 的畫中畫支援
  • PiP 激活的簡單 API
  • 自動畫中畫狀態處理
  • 可自定畫中畫大小和位置
  • 與 Android 的畫中畫 API 集成

適合對象

  • 影片播放器應用
  • 音頻串流應用
  • 帶有媒體內容的教育類應用程式
  • 需要多任務功能的應用程式
  • 針對Android設備的開發者

使用建議

  • 僅在 Android 上可用
  • 需要 Android 8.0+(API 26)
  • 僅限媒體播放場景
  • 無 iOS 支援
  • 必須正確處理畫中畫生命週期事件

原始 README

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

floating

codecov

Picture in Picture management for Flutter. Android only

Picture in picture demo

App configuration

Add android:supportsPictureInPicture="true" line to the <activity> tag in android/src/main/AndroidManifest.xml:

<manifest>
   <application>
        <activity
            android:name=".MainActivity"
            android:supportsPictureInPicture="true"
            ...

Widget

This package provides a helper PiPSwitcher widget for switching the displayed widgets according to current PiP status. Use it like so:

PiPSwitcher(
    childWhenDisabled: Scaffold(...),
    childWhenEnabled: JustVideo(), 
)

API

PiP mode in desired mode is available only in Android so iOS and web support is not planned until the platforms adds native support for such feature.

Create a Floating instance
final floating = Floating();
Check if PiP is available
final canUsePiP = await floating.isPipAvailable;

PiP may be unavailable because of system settings managed by admin or device manufacturer. Also, the device may have Android version that was released without this feature.

Check if app is in PiP mode
final currentStatus = await floating.pipStatus;

Possible statuses:

Status Description Will enable() have an effect?
disabled PiP is available to use but currently disabled. Yes
enabled PiP is enabled. The app can display content but will not receive user inputs until the user decides to bring the app to it's full size. No
automatic PiP will be enabled automatically by the OS. Yes
unavailable PiP is disabled on given device. No
Enable PiP mode

Enable PiP right away:

final statusAfterEnabling = await floating.enable(ImmediatePiP());

Enable PiP when the app gets minimized via system gesture:

final statusAfterEnabling = await floating.enable(OnLeavePiP());

To later cancel, use .cancelOnLeavePiP().

When enabled, PiP mode can be toggled off by the user via system UI.

Arguments
aspectRatio:

The default 16/9 aspect ratio can be overridden with custom Rational. Eg. to make PiP square use: .enable(aspectRatio: Rational(1, 1)) or .enable(aspectRatio: Rational.square()).

sourceRectHint:

By default, system will simply use fade animation to tween between full app and PiP. Switching animation can be smoother by using source rect hint (example animation).

Check the example project to see an example of usage.

所屬分類

原始碼儲存庫

使用此套件的專案