Using the Superwall Delegate
Use SuperwallDelegate in Flutter to forward Superwall events to analytics, handle custom paywall actions, and react to subscription status and paywall events.
Use Superwall's delegate to extend our SDK's functionality across several surface areas by assigning to the delegate property:
import 'package:superwallkit_flutter/superwallkit_flutter.dart';
class SWDelegate extends SuperwallDelegate {
// Implement delegate methods here
}
// When configuring the SDK...
void configureSDK() {
Superwall.shared.setDelegate(SWDelegate());
}Some common use cases for using the Superwall delegate include:
- Custom actions: Respond to custom tap actions from a paywall.
- Respond to purchases: See which product was purchased from the presented paywall.
- Analytics: Forward events from Superwall to your own analytics.
Below are some commonly used implementations when using the delegate.
Superwall Events
Most of what occurs in Superwall can be viewed using the delegate method to respond to events:
class _MyAppState extends State<MyApp> implements SuperwallDelegate {
@override
Future<void> handleSuperwallEvent(SuperwallEventInfo eventInfo) async {
switch (eventInfo.event.type) {
// Handle any other event types as needed
case PlacementType.transactionComplete:
final product = eventInfo.params?['product'];
logging.info('Transaction complete event received with product: $product');
break;
default:
logging.info('Unhandled event type: ${eventInfo.event.type}');
break;
}
}
}Paywall Custom Actions
Using the custom tap action, you can respond to any arbitrary event from a paywall:
class _MyAppState extends State<MyApp> implements SuperwallDelegate {
final logging = Logging();
@override
void handleCustomPaywallAction(String name) {
logging.info('handleCustomPaywallAction: $name');
}
}Subscription status changes
You can be informed of subscription status changes using the delegate. If you need to set or handle the status on your own, use a purchase controller — this function is only for informational, tracking or similar purposes:
class _MyAppState extends State<MyApp> implements SuperwallDelegate {
final logging = Logging();
@override
void subscriptionStatusDidChange(SubscriptionStatus newValue) {
logging.info('subscriptionStatusDidChange: $newValue');
}
}Paywall events
The delegate also has callbacks for several paywall events, such dismissing, presenting, and more. Here's an example:
class _MyAppState extends State<MyApp> implements SuperwallDelegate {
final logging = Logging();
@override
void didPresentPaywall(PaywallInfo paywallInfo) {
logging.info('didPresentPaywall: $paywallInfo');
}
}How is this guide?
Advanced Configuration
When configuring the SDK you can pass in options that configure Superwall, the paywall presentation, and its appearance.
3rd Party Analytics
Forward Superwall events to your own analytics in a Flutter app: implement handleSuperwallEvent on SuperwallDelegate and send each event and its params.