Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    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.

    View on pub.devpub.dev • iOS 15+ • Android 24+ • SPM or CocoaPods

    1. Install

    Terminal
    flutter pub add billdog_flutter:^1.2.0-beta.1

    …or add it to your pubspec directly:

    pubspec.yaml
    dependencies:
      billdog_flutter: ^1.2.0-beta.1

    2. Raise the platform minimums: iOS 15.0, Android minSdk 24

    Uncomment (or add) the platform line at the top of ios/Podfile:

    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.

    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/app/build.gradle.kts
    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.

    main.dart
    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:

    Dart
    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.

    Dart
    // 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:

    Dart
    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:

    Dart
    PaywallView(
      identifier: 'premium_offer',
      onPurchase: (productId, data) => Navigator.of(context).pop(),
      onDismiss: () => Navigator.of(context).pop(),
    )

    6. Check entitlements

    Dart
    // 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();

    7. Track events

    Dart
    await BillDog.shared.trackEvent(
      'app_opened',
      properties: {'source': 'cold_start'},
    );

    8. Authentication — sign users in

    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.

    Dart
    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
      );
    }

    Passwordless, and phone numbers

    Dart
    // 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,
    );

    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

    Dart
    // 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:

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.