floating 6.0.0 copy "floating: ^6.0.0" to clipboard
floating: ^6.0.0 copied to clipboard

PlatformAndroid

Picture in Picture mode management for Flutter. Available only for Android.

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"
            ...
copied to clipboard

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(), 
)
copied to clipboard

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();
copied to clipboard

Check if PiP is available #

final canUsePiP = await floating.isPipAvailable;
copied to clipboard

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;
copied to clipboard

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());
copied to clipboard

Enable PiP when the app gets minimized via system gesture:

final statusAfterEnabling = await floating.enable(OnLeavePiP());
copied to clipboard

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.

228
likes
160
points
11k
downloads
screenshot

Publisher

verified publisherwrbl.xyz

Weekly Downloads

2024.09.22 - 2025.04.06

Picture in Picture mode management for Flutter. Available only for Android.

Repository (GitHub)

Topics

#widget #picture-in-picture #android #flutter

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on floating