Add a paywall and subscriptions to a Flutter app
To add a paywall to a Flutter app with BillDog, add billdog_flutter, set iOS 15 and Android minSdk 24, call BillDog.configure(apiKey) in main(), then await BillDog.shared.register('onboarding') where the paywall belongs. The same Dart code sells through the App Store and Google Play, and getCustomerInfo() tells you whether to unlock.
Steps last checked against the SDK source on 15 Nov 2026.
What you'll build
- One Dart code path that shows a paywall on iOS and Android
- Content gated on the
premiumentitlement - Restore Purchases wired to the result type
What you'll need
- Flutter 3.10+ with Dart 3
- A free BillDog project (sign up)
- A real device or simulator for each platform you test
- Products in the stores you sell through (App Store setup, Google Play setup)
1. Install the package
2 minflutter pub add billdog_flutter:^1.2.0-beta.1Or add it to pubspec.yaml yourself:
dependencies:
billdog_flutter: ^1.2.0-beta.12. Raise the platform minimums
2 minThe Flutter template targets iOS 13. BillDog needs iOS 15 and Android minSdk 24; without these, pod install fails on the iOS deployment target and the Android build fails on minSdk.
platform :ios, '15.0'Also set iOS Deployment Target to 15.0 on the Runner target in Xcode, so the app and the pods agree. With Swift Package Manager enabled there may be no Podfile at all, but the Runner target still needs 15.0.
android {
defaultConfig {
minSdk = 24
}
}3. Set up the product, paywall and placement
12 minYour app asks BillDog for a placement (a named moment such as onboarding), and the dashboard decides which paywall to show there. That means you can change the paywall later without shipping an app update. Four things need to be connected: a product, an entitlement it grants, an offering that sells it, and a placement that serves the offering's paywall.
- Use the Public Sandbox API Key shown when you created the project. It starts with
bd_public_test_. Didn't save it? The API Keys list shows only a prefix, so make a new one: open Integration & Data → API Keys, click Generate API Key, enter a Key Name, choose Environment: Sandbox and Key Type: Public (Client), then copy the key from the dialog. It is shown only once. Ship only public keys in an app;bd_secret_keys are for servers. - Open Monetization → Products and click New Product. Keep Product Kind: Store. The Product Identifier is BillDog's own ID for the product. Set Product Type to Subscription and choose a Subscription Duration. Put the exact store IDs in App Store Product ID and Play Store Product ID. A product with no ID for a store is not served on that platform. Enable Web Checkout is on by default; its price is only used for Stripe on the web. Products not in the store yet? See App Store setup or Google Play setup.
- Open Monetization → Entitlements, click New Entitlement, use the identifier
premium(with any Display Name), and under Product Mapping tick the product. New projects also come with aproentitlement and a Default Offering; this codelab uses its own. Without this mapping a purchase succeeds but unlocks nothing. - Open Monetization → Offerings, click New Offering, give it an Identifier and Display Name, tick Mark as current offering and click Create Offering. The offering editor opens: click Add Product, tick your product, type a Package Identifier such as
monthly, click Add Package, then Save Changes. - Open Paywalls & Funnels → Create New → Single Paywall, choose Use Template and pick one. In the builder, open the Products panel (the box icon in the left rail) and choose your offering under Offering.
- Templates are designs: their buttons aren't wired to buy anything. Select the main button, and under Tap Actions click Add First Action and choose Purchase. Give the close button (or a secondary button) a Close Paywall action if it has none: publishing refuses a paywall with no way out.
- Click Publish (then Save & Publish). A warning that "nothing on this paywall starts a purchase" means the main button still has no Purchase action. Check the paywall shows Live under Paywalls & Funnels → All Paywalls. An unpublished paywall serves nothing.
- Open Monetization → Placements, click Create Placement, set the Identifier to
onboardingand a Display Name, and click Create. Then click the link icon on the placement's row, tick your offering, tick Default and click Link Offerings. - In the same Create Placement dialog (or later on the placement's page), turn on Requires access and choose
premiumas the Required Entitlement. Subscribers then skip the paywall instead of seeing it again.
Placement identifiers are case-sensitive. A mistyped identifier is created as an empty placement (you'll see it under Placements), and register comes back with a "no paywall configured" error. If nothing shows, see Fix a paywall that doesn't show.
4. Configure the SDK in main()
2 minThe API key is a positional argument. After configure completes, use BillDog.shared everywhere else.
import 'package:flutter/material.dart';
import 'package:billdog_flutter/billdog_flutter.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await BillDog.configure(
'bd_public_test_YOUR_KEY',
options: const BillDogOptions(enableLogging: true),
);
runApp(const MyApp());
}5. Show the paywall for a placement
5 minregister returns a sealed PlacementResult, so a Dart 3 switch covers every case. It returns PlacementError instead of throwing.
Future<void> showPaywall() async {
final result = await BillDog.shared.register('onboarding');
switch (result) {
case PlacementPurchased() || PlacementEntitled() || PlacementRestored():
setState(() => isPro = true);
case PlacementError(:final message):
debugPrint('Placement failed: $message');
default:
break; // PlacementDismissed, PlacementHoldout, PlacementOAuthSuccess
}
}6. Unlock content with the entitlement
3 minFuture<void> refreshAccess() async {
try {
final info = await BillDog.shared.getCustomerInfo();
setState(() => isPro = info.hasEntitlement('premium'));
} catch (e) {
// A BillDogError, or a StateError if the native plugin is missing
debugPrint('Could not read entitlements: $e');
setState(() => isPro = false); // treat errors as locked
}
}Call this on startup, for example from initState, so returning subscribers are unlocked before they reach a paywall.
7. Add Restore Purchases
3 minfinal r = await BillDog.shared.restorePurchases();
switch (r) {
case RestoredItems(:final items):
debugPrint('Restored ${items.length}');
case RestoreFailed(:final error):
debugPrint('Restore failed: ${error.message}');
}
final info = await BillDog.shared.getCustomerInfo(
policy: CacheFetchPolicy.fetchCurrent,
);
setState(() => isPro = info.hasEntitlement('premium'));CacheFetchPolicy.fetchCurrent skips the cache so the UI shows the restored state straight away.
8. Optional: identify signed-in users
2 minAn anonymous ID is created on first launch. Identify users when they sign in so purchases follow them across devices.
await BillDog.shared.identify('user_123');
// On sign-out
await BillDog.shared.logOut();Before release, switch to your bd_public_live_ key. To buy in the store sandboxes, see iOS sandbox testing and Google Play testing.