enterIfAvailable static method

Future<bool> enterIfAvailable({
  1. double? aspectRatio,
})

Implementation

static Future<bool> enterIfAvailable({double? aspectRatio}) async {
  if (!Platform.isAndroid) return false;
  try {
    final Map<String, dynamic> args = {};
    if (aspectRatio != null) {
      // Convert double to rational numerator/denominator (simplified)
      if (aspectRatio > 2.39) aspectRatio = 2.39; // Android max limit
      if (aspectRatio < 0.418) aspectRatio = 0.418; // Android min limit

      args['numerator'] = (aspectRatio * 1000).toInt();
      args['denominator'] = 1000;
    }

    final result = await _channel.invokeMethod<bool>('enterPictureInPicture', args);
    return result ?? false;
  } catch (_) {
    return false;
  }
}