diff --git a/content/docs/flutter/index.mdx b/content/docs/flutter/index.mdx index b7ba729..89b528c 100644 --- a/content/docs/flutter/index.mdx +++ b/content/docs/flutter/index.mdx @@ -34,4 +34,4 @@ If you have feedback on any of our docs, please leave a rating and message at th If you have any issues with the SDK, please [open an issue on GitHub](https://github.com/superwall/superwall-flutter/issues). - \ No newline at end of file + \ No newline at end of file diff --git a/content/docs/flutter/quickstart/tracking-subscription-state.mdx b/content/docs/flutter/quickstart/tracking-subscription-state.mdx index e00e9ee..3a5b978 100644 --- a/content/docs/flutter/quickstart/tracking-subscription-state.mdx +++ b/content/docs/flutter/quickstart/tracking-subscription-state.mdx @@ -54,6 +54,18 @@ The `SubscriptionStatus` enum has three possible values: - `SubscriptionStatus.active` - User has an active subscription - `SubscriptionStatus.inactive` - User has no active subscription +Use the `isActive` convenience property when you only need to know if the user is subscribed: + +```dart +Superwall.shared.subscriptionStatus.listen((status) { + if (status.isActive) { + _showPremiumContent(); + } else { + _showFreeContent(); + } +}); +``` + ## Using SuperwallBuilder widget For reactive UI updates based on subscription status, use the `SuperwallBuilder` widget: @@ -100,13 +112,14 @@ class PremiumFeatureButton extends StatelessWidget { stream: Superwall.shared.subscriptionStatus, builder: (context, snapshot) { final status = snapshot.data ?? SubscriptionStatus.unknown; + final isActive = status.isActive; return ElevatedButton( - onPressed: status == SubscriptionStatus.active + onPressed: isActive ? _accessPremiumFeature : _showPaywall, child: Text( - status == SubscriptionStatus.active + isActive ? 'Access Premium Feature' : 'Upgrade to Premium', ), @@ -133,7 +146,7 @@ If you need to check the subscription status at a specific moment without listen Future checkSubscription() async { // Note: You'll need to get the current value from the stream final subscription = Superwall.shared.subscriptionStatus.listen((status) { - if (status == SubscriptionStatus.active) { + if (status.isActive) { // User is subscribed enablePremiumFeatures(); } else { diff --git a/content/docs/flutter/sdk-reference/PaywallOptions.mdx b/content/docs/flutter/sdk-reference/PaywallOptions.mdx index fbcc24d..34cab30 100644 --- a/content/docs/flutter/sdk-reference/PaywallOptions.mdx +++ b/content/docs/flutter/sdk-reference/PaywallOptions.mdx @@ -22,6 +22,7 @@ class PaywallOptions { bool shouldShowWebRestorationAlert = true; Map? overrideProductsByName; bool shouldShowWebPurchaseConfirmationAlert = true; + void Function(PaywallInfo?)? onBackPressed; } class RestoreFailed { @@ -49,6 +50,7 @@ enum TransactionBackgroundView { spinner, none } | `shouldShowWebRestorationAlert` | `bool` | Shows an alert asking the user to try restoring on the web if web checkout is enabled. Defaults to `true`. | | `overrideProductsByName` | `Map?` | Overrides products on all paywalls using name→identifier mapping (e.g., `"primary"` → `"com.example.premium_monthly"`). | | `shouldShowWebPurchaseConfirmationAlert` | `bool` | Shows a localized alert confirming a successful web checkout purchase. Defaults to `true`. | +| `onBackPressed` | `void Function(PaywallInfo?)?` | Android only. Invoked when the system back button is pressed while a paywall is visible. Call `Superwall.shared.dismiss()` inside if you want to close the paywall. | ## Usage @@ -64,7 +66,11 @@ final paywallOptions = PaywallOptions() 'tertiary': 'com.example.premium_annual', } ..shouldShowWebRestorationAlert = true - ..shouldShowWebPurchaseConfirmationAlert = true; + ..shouldShowWebPurchaseConfirmationAlert = true + ..onBackPressed = (paywallInfo) { + // Android-only callback + Superwall.shared.dismiss(); + }; final options = SuperwallOptions( paywalls: paywallOptions, diff --git a/content/docs/flutter/sdk-reference/index.mdx b/content/docs/flutter/sdk-reference/index.mdx index 78bef29..0239f4e 100644 --- a/content/docs/flutter/sdk-reference/index.mdx +++ b/content/docs/flutter/sdk-reference/index.mdx @@ -15,4 +15,4 @@ If you have feedback on any of our docs, please leave a rating and message at th If you have any issues with the SDK, please [open an issue on GitHub](https://github.com/superwall/superwall-flutter/issues). - \ No newline at end of file + \ No newline at end of file diff --git a/content/docs/flutter/sdk-reference/subscriptionStatus.mdx b/content/docs/flutter/sdk-reference/subscriptionStatus.mdx index 081307e..12e1eec 100644 --- a/content/docs/flutter/sdk-reference/subscriptionStatus.mdx +++ b/content/docs/flutter/sdk-reference/subscriptionStatus.mdx @@ -18,6 +18,21 @@ Stream get subscriptionStatus ## Returns / State Returns a `Stream` that emits values whenever the subscription status changes. +## Convenience +Use the `isActive` convenience property when you only need to know whether the user is subscribed: + +```dart +Future ensureAccess() async { + final status = await Superwall.shared.subscriptionStatus.first; + + if (status.isActive) { + enablePremiumFeatures(); + } else { + showUpgradePrompt(); + } +} +``` + ## Usage Basic stream subscription: