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
- Call
configure()when your app starts, before anyPaywallViewis built. - Put a
PaywallViewin a parent with a bounded size, such as aSizedBoxor anExpanded. It fills the space its parent gives it. - Set
placementto a placement that has a campaign on the Superwall dashboard. - In
onFinished, check theresultand unlock the feature if the user purchased or restored. - When
onFinishedreportsshouldDismissastrue, remove thePaywallViewfrom 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
PaywallViewworks on Android and iOS only. On other platforms it showserrorBuilderwith the errorPaywallView is only available on Android and iOS.- There's no
featurecallback like the one onregisterPlacement(). The result arrives inonFinished, 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 showserrorBuilderwith the errorSuperwall 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
onFinishedreportsshouldDismissastrue, the view renders nothing. onLoadingStateChangedandonCustomCallbackare iOS only.
Related
- Retrieving and Presenting a Paywall Yourself
registerPlacement()presents a placement's paywall over the app.PaywallPresentationHandlerhas the same callbacks for a presented paywall.PaywallOptionssetsautomaticallyDismiss, which controlsshouldDismissafter a purchase or restore.
How is this guide?