PaywallView

Embed a placement's paywall inside your own Flutter widget tree with the PaywallView widget, instead of presenting it over the app.

Purpose

PaywallView is a widget that shows the paywall for a placement inside your own layout, such as a section of a screen, a tab or an onboarding page. Use it when the paywall should be part of a screen instead of being presented over the app by registerPlacement().

The widget retrieves the paywall when it's first built. While it loads, it shows loadingBuilder. If the user shouldn't see a paywall, it shows skippedBuilder, and if the paywall couldn't be retrieved, it shows errorBuilder.

PaywallView is available in Flutter SDK 2.9.0 and later, on Android and iOS. Call configure() before you build one.

Signature

class PaywallView extends StatefulWidget {
  const PaywallView({
    Key? key,
    required String placement,
    Map<String, Object>? params,
    void Function(PaywallInfo paywallInfo)? onPresent,
    void Function(PaywallInfo paywallInfo, PaywallResult result, bool shouldDismiss)? onFinished,
    void Function(PaywallSkippedReason reason)? onSkip,
    void Function(String error)? onError,
    WidgetBuilder? loadingBuilder,
    Widget Function(BuildContext context, PaywallSkippedReason reason)? skippedBuilder,
    Widget Function(BuildContext context, String error)? errorBuilder,
    void Function(PaywallLoadingState state)? onLoadingStateChanged, // iOS only
    Future<CustomCallbackResult> Function(CustomCallback callback)? onCustomCallback, // iOS only
    Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
  });
}

Parameters

Prop

Type

PaywallLoadingState

onLoadingStateChanged receives one of these values:

Prop

Type

Add a paywall to a screen

  1. Call configure() when your app starts, before any PaywallView is built.
  2. Put a PaywallView in a parent with a bounded size, such as a SizedBox or an Expanded. It fills the space its parent gives it.
  3. Set placement to a placement that has a campaign on the Superwall dashboard.
  4. In onFinished, check the result and unlock the feature if the user purchased or restored.
  5. When onFinished reports shouldDismiss as true, remove the PaywallView from your widget tree.
import 'package:flutter/material.dart';
import 'package:superwallkit_flutter/superwallkit_flutter.dart';

class UpgradeCard extends StatefulWidget {
  const UpgradeCard({super.key});

  @override
  State<UpgradeCard> createState() => _UpgradeCardState();
}

class _UpgradeCardState extends State<UpgradeCard> {
  bool _showPaywall = true;
  bool _isPro = false;

  @override
  Widget build(BuildContext context) {
    if (_isPro) {
      return const Text('Thanks for upgrading!');
    }
    if (!_showPaywall) {
      return const SizedBox.shrink();
    }

    return SizedBox(
      height: 500,
      child: PaywallView(
        placement: 'upgrade_card',
        params: {'source': 'home_screen'},
        loadingBuilder: (context) =>
            const Center(child: CircularProgressIndicator()),
        skippedBuilder: (context, reason) => const SizedBox.shrink(),
        errorBuilder: (context, error) =>
            const Center(child: Text('This offer is unavailable.')),
        onPresent: (paywallInfo) {
          debugPrint('Showing ${paywallInfo.name}');
        },
        onFinished: (paywallInfo, result, shouldDismiss) {
          setState(() {
            switch (result) {
              case PurchasedPaywallResult():
              case RestoredPaywallResult():
                _isPro = true;
              case DeclinedPaywallResult():
                break;
            }
            if (shouldDismiss) {
              _showPaywall = false;
            }
          });
        },
      ),
    );
  }
}

Inside a scroll view

By default, the paywall claims every gesture that starts on it, so the paywall scrolls instead of its parent. To let a parent ListView scroll when the user drags across the paywall, pass an empty set:

SizedBox(
  height: 400,
  child: PaywallView(
    placement: 'inline_offer',
    gestureRecognizers: const {},
  ),
)

Limitations

  • PaywallView works on Android and iOS only. On other platforms it shows errorBuilder with the error PaywallView is only available on Android and iOS.
  • There's no feature callback like the one on registerPlacement(). The result arrives in onFinished, where you decide whether to unlock the feature.
  • Don't show the same paywall in two PaywallViews at once. The native SDKs share one paywall instance per paywall, so give each mounted view a placement that leads to a different paywall.
  • Call Superwall.configure() first. Otherwise the view shows errorBuilder with the error Superwall must be configured before a PaywallView is shown.
  • Each view shows one placement with one set of params. When either changes, the view is recreated and the paywall is retrieved again.
  • After onFinished reports shouldDismiss as true, the view renders nothing.
  • onLoadingStateChanged and onCustomCallback are iOS only.

How is this guide?

On this page