presentPaywall static method

Future<PaywallResult> presentPaywall({
  1. Offering? offering,
  2. bool displayCloseButton = false,
  3. Map<String, CustomVariableValue>? customVariables,
  4. PaywallPresentationConfiguration? presentationConfiguration,
})

Presents the paywall as an activity on android or a modal in iOS. Returns a PaywallResult indicating the result of the paywall presentation. @param offering If set, will present the paywall associated to the given Offering. @param displayCloseButton Optionally present the paywall with a close button. Only available for original template paywalls. Ignored for V2 Paywalls. @param customVariables A map of custom variable names to their values. These values can be used for text substitution in paywalls using the {{ custom.variable_name }} syntax. @param presentationConfiguration Optional configuration for how the paywall is presented on each platform.

Implementation

static Future<PaywallResult> presentPaywall({
  Offering? offering,
  bool displayCloseButton = false,
  Map<String, CustomVariableValue>? customVariables,
  PaywallPresentationConfiguration? presentationConfiguration,
}) async {
  final presentedOfferingContext = offering?.availablePackages
      .elementAtOrNull(0)
      ?.presentedOfferingContext;
  final result = await _methodChannel.invokeMethod('presentPaywall', {
    'offeringIdentifier': offering?.identifier,
    'presentedOfferingContext': presentedOfferingContext?.toJson(),
    'displayCloseButton': displayCloseButton,
    'customVariables': convertCustomVariablesToNative(customVariables),
    // Only send when fullScreen is explicitly requested; omitting the key
    // lets the native SDK use its default (sheet). This avoids ambiguity
    // between "key absent" and "key present with false".
    if (presentationConfiguration?.ios ==
        IOSPaywallPresentationStyle.fullScreen)
      'useFullScreenPresentation': true,
  });
  return _parseStringToResult(result);
}