simple_pip_mode 0.5.1 copy "simple_pip_mode: ^0.5.1" to clipboard
simple_pip_mode: ^0.5.1 copied to clipboard

outdated

A complete Picture-In-Picutre mode plugin (Android support only)

Pub page License

A complete Picture-In-Picture mode plugin for android API level 26+ (Android Oreo).

Provides methods to check feature availability, enter PIP mode and callbacks.

pip_example

Features #

  • Verify PIP system availability and current state.
  • Method to enter PIP mode, with aspect ratio, auto enter and seamless resize parameters.
  • On PIP mode change Callbacks.
  • Widget to build PIP-dependent layouts.

Installation #

In the dependencies: section of your pubspec.yaml, add the following line:

  simple_pip_mode: <latest_version>

Usage #

This section has example code for the following tasks:

Update manifest #

Add android:supportsPictureInPicture="true" to the activity on your AndroidManifest.xml.

Verify pip support #

Use SimplePip.isPipAvailable and SimplePip.isPipActivated static getters to verify whether the device supports Picture In Picture feature and the feature is currently activated respectively.

Entering pip mode #

Import simple_pip.dart file and call enterPipMode method.

import 'package:simple_pip_mode/simple_pip.dart';

class MyWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return IconButton(
      icon: Icon(Icons.picture_in_picture),
      onPressed: () => SimplePip().enterPipMode(),
    );
  }
}

Enabling callbacks #

In your main activity kotlin file import the callback helper.

import cl.puntito.simple_pip_mode.PipCallbackHelper

Instance a callback helper, provide the flutter engine to it, and finally, call helper on callback.

class MainActivity: FlutterActivity() {
  //...
  private var callbackHelper = PipCallbackHelper()
  //...
  override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    callbackHelper.configureFlutterEngine(flutterEngine)
  }
  
  override fun onPictureInPictureModeChanged(active: Boolean, newConfig: Configuration?) {
    callbackHelper.onPictureInPictureModeChanged(active)
  }
  //...
}

Done! now you can use PIP callbacks and the PIP widget.

Using callbacks #

To use callbacks, just pass them as parameters to SimplePip constructor.

SimplePip _pip = SimplePip(
  onPipEntered: () => doSomething(),
  onPipExited: () => doSomeOtherThing(),
);

Using the PIP widget #

To use the widget, you need to enable callbacks first. Import pip_widget.dart file.

import 'package:simple_pip_mode/pip_widget.dart';
class MyWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return PipWidget(
      builder: (context) => Text('This is built when PIP mode is not active'),
      pipBuilder: (context) => Text('This is built when PIP mode is active'),
    );
  }
}

You can also pass callbacks directly to PipWidget.

Contribute #

I'm currently working on more features, so issues and pull requests are appreciated!

49
likes
0
pub points
90%
popularity

Publisher

verified publisherpuntito.cl

A complete Picture-In-Picutre mode plugin (Android support only)

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on simple_pip_mode