enable method

Future<PiPStatus> enable({
  1. Rational aspectRatio = const Rational.landscape(),
  2. Rectangle<int>? sourceRectHint,
})

Turns on PiP mode.

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

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.

Provide aspectRatio to override default 16/9 aspect ratio. aspectRatio must fit into Android-supported values: min: 1/2.39, max: 2.39/1, otherwise RationalNotMatchingAndroidRequirementsException will be thrown. Note: this will not make any effect on Android SDK older than 26.

Implementation

Future<PiPStatus> enable({
  Rational aspectRatio = const Rational.landscape(),
  Rectangle<int>? sourceRectHint,
}) async {
  if (!aspectRatio.fitsInAndroidRequirements) {
    throw RationalNotMatchingAndroidRequirementsException(aspectRatio);
  }

  final bool? enabledSuccessfully = await _channel.invokeMethod(
    'enablePip',
    {
      ...aspectRatio.toMap(),
      if (sourceRectHint != null)
        'sourceRectHintLTRB': [
          sourceRectHint.left,
          sourceRectHint.top,
          sourceRectHint.right,
          sourceRectHint.bottom,
        ],
    },
  );
  return enabledSuccessfully ?? false
      ? PiPStatus.enabled
      : PiPStatus.unavailable;
}