Flutter SDK Guide
💙 Flutter — a Dart bridge over the native SDKs
The Flutter plugin is a thin bridge: Dart calls delegate to the native BillDog iOS and Android SDKs over a method channel, so billing and paywall behaviour match the native guides.
1. Install
flutter pub add billdog_flutter:^1.2.0-beta.1…or add it to your pubspec directly:
dependencies:
billdog_flutter: ^1.2.0-beta.12. Raise the platform minimums: iOS 15.0, Android minSdk 24
Required — the build fails without it
pod install fails with "The plugin "billdog_flutter" requires a higher minimum iOS deployment version than your application is targeting."Uncomment (or add) the platform line at the top of ios/Podfile:
platform :ios, '15.0'Also set iOS Deployment Target to 15.0 for the Runner target in Xcode, so the app and the pods agree.
Swift Package Manager projects
Runner target.Android: minSdk 24
The plugin’s Android library declares minSdk 24. Flutter’s app template uses flutter.minSdkVersion, which is 24 on current Flutter but lower on older releases. If yours is lower, the Android build stops at the manifest merge; set it in android/app/build.gradle.kts (or minSdk 24 in android/app/build.gradle):
android {
defaultConfig {
minSdk = 24
}
}3. Configure
Configure once at startup. The API key is a positional argument. configure returns the instance and also populates the BillDog.shared accessor used everywhere below.
import 'package:billdog_flutter/billdog_flutter.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await BillDog.configure('YOUR_API_KEY_HERE'); // bd_public_test_… or bd_public_live_…
runApp(const MyApp());
}Options are passed separately:
await BillDog.configure(
'YOUR_API_KEY_HERE',
options: const BillDogOptions(
enableLogging: true,
environment: NetworkEnvironment.production,
),
);
BillDog.isConfigured; // -> bool (static getter)4. Manage customer identity
This links a user you have already authenticated elsewhere. If you would rather BillDog signed them in — password, email or SMS code, Google, Apple, passkeys, second factors, organizations — see BillDog Auth. The session it issues carries the user’s entitlements in the token, so your backend gates a paid feature with a claim check instead of a round-trip. See §8 Authentication below.
// Link this device to your account id
await BillDog.shared.logIn('user_uuid_123');
// …or identify directly
await BillDog.shared.identify('user_uuid_123');
BillDog.shared.getAppUserId(); // -> String?
// On logout: continue as a NEW anonymous user (a fresh anonymous id)
await BillDog.shared.logOut();5. Present a paywall
Register a placement and let BillDog apply your targeting rules. The result is a sealed set of cases:
final result = await BillDog.shared.register('onboarding');
if (result is PlacementPurchased) {
// result.productId
} else if (result is PlacementEntitled) {
// already had access
} else if (result is PlacementDismissed) {
// closed without purchasing
} else if (result is PlacementError) {
// result.message
}Or embed a specific paywall as a widget:
PaywallView(
identifier: 'premium_offer',
onPurchase: (productId, data) => Navigator.of(context).pop(),
onDismiss: () => Navigator.of(context).pop(),
)6. Check entitlements
// Asks the server whether the placement's access requirement is met
if (await BillDog.shared.hasAccessForPlacement('premium_features')) {
// unlock
}
// Or read the full customer record
final info = await BillDog.shared.getCustomerInfo();
final hasPro = info.entitlements.any(
(e) => e.identifier == 'pro' && e.isActive,
);
// Restore purchases (e.g. from a "Restore" button)
await BillDog.shared.restorePurchases();Entitlements are a List, not a Map
CustomerInfo.entitlements is a List<Entitlement> — identifier, isActive, expiresAt, willRenew, isLifetime — so use .any(...) rather than indexing by key.7. Track events
await BillDog.shared.trackEvent(
'app_opened',
properties: {'source': 'cold_start'},
);8. Authentication — sign users in
Requires native binaries 1.0.2-beta.3 or later (use 1.2.0-beta.1)
io.billdog:billdog-auth exists on Maven Central only from 1.0.2-beta.3. Every call below crosses the method channel into that native module, so against older binaries there is nothing on the other side.Nothing extra goes in pubspec.yaml: BillDogAuth ships inside billdog_flutter. As everywhere else in this plugin, Dart delegates to the native SDKs rather than reimplementing them — which is why the refresh token lives in the iOS Keychain and Android EncryptedSharedPreferences, never in shared_preferences, which is plain text on disk.
import 'package:billdog_flutter/billdog_flutter.dart';
final auth = BillDogAuth.instance;
await auth.restore(); // AuthRestoreResult(signedIn: false) on first launch
final r = await auth.attempt(
identifier: 'ada@example.com',
strategy: 'password',
password: password,
);
// Check this BEFORE treating it as a sign-in: against an enrolled account a
// correct password issues no session.
if (r.mfaRequired) {
await auth.attempt(
identifier: 'ada@example.com',
strategy: 'totp',
code: code,
mfaToken: r.mfaToken, // proves the first factor was accepted
);
}A wrong second factor is a restart, not a retry
mfaToken. Send the user back to the first factor for a fresh one; calling attempt again with the same token only fails again.Passwordless, and phone numbers
// A RETURNING user gets a fresh code from requestCode. Without it a code could
// only be obtained as a side effect of signing up.
await auth.requestCode(identifier: '+15551234567', kind: 'phone');
await auth.attempt(
identifier: '+15551234567',
kind: 'phone', // REQUIRED — selects the identity row
strategy: 'sms_code',
code: code,
);kind defaults to 'email' and selects the identity row
The rest of the surface: isSignedIn(), signUp(...), signOut(scope: ...) over 'this' | 'others' | 'all', passkeysAvailable(), registerPasskey(), signInWithPasskey(), and BillDogOrganizations — create, list, members, roles, invitations, domains. Strategies are password, email_code, sms_code, totp, backup_code.
Sign-up requirements, password reset and account deletion
// What the project requires before it accepts a sign-up
final cfg = await auth.config(); // accessMode, botProtection, turnstileSiteKey, ...
await auth.signUp(
identifier: 'ada@example.com',
password: password,
invitationToken: invitationToken, // required when cfg.accessMode is 'invite_only'
captchaToken: captchaToken, // required when cfg.botProtection is true (a Turnstile token)
);
// Password reset: send a code, then set the new password with it.
// Pass the same kind to both calls for a phone number.
await auth.requestPasswordReset(identifier: 'ada@example.com');
await auth.resetPassword(
identifier: 'ada@example.com',
code: code,
newPassword: newPassword,
);
// Delete the signed-in user's own account. Throws ReauthRequiredError when
// the sign-in is too old: sign the user in again, then retry.
await auth.deleteAccount();Full detail: BillDog Auth, Sessions & Tokens, Multi-Factor, Hosted vs Native.
Next steps
- The plugin delegates to the native SDKs; for platform behaviour see the iOS and Android guides.
- SDK glossary — placements, offerings and entitlements explained.
- BillDog Auth — sign users in, and gate features on the token.
Was this page helpful?
Or rate this page: