purchases_flutter

The RevenueCat SDK for Flutter on iOS, Android, macOS, and web. It wraps StoreKit and Google Play Billing and handles purchases and entitlements.

pub.dev version License: MIT

Docs · Install guide · SDK reference · Sample app · Changelog · Migration guide

Requirements

Requirement Minimum
Flutter 3.41
Dart 3.11
iOS 13.0
macOS 10.15
Android 7.0 (API level 24)
Web Supported
Android compile SDK API 35
Kotlin (Android) 2.1.0
Xcode 15.0

purchases_ui_flutter supports iOS and Android only, so Paywalls and Customer Center aren't available on web or macOS. They need iOS 15 or later and Android 7.0 (API level 24) or later.

Installation

Add purchases_flutter, plus purchases_ui_flutter if you show Paywalls or Customer Center:

flutter pub add purchases_flutter purchases_ui_flutter

If your app doesn't show Paywalls or Customer Center, add only the core package: flutter pub add purchases_flutter.

Then import the SDK in each file that uses it:

import 'package:purchases_flutter/purchases_flutter.dart';
  • iOS and macOS: the SDK requires Swift Package Manager (SPM). Flutter 3.44 and later enable SPM unless your app turns it off; on Flutter 3.41 to 3.43, run flutter config --enable-swift-package-manager on every developer machine and in CI. If your app installs RevenueCat with CocoaPods, follow the CocoaPods to SPM migration guide before you upgrade. Other plugins can keep using CocoaPods.
  • iOS: add the In-App Purchase capability in Xcode before you make App Store purchases, in sandbox or production (steps). The Test Store works without it.
  • Android: the Activity that starts purchases needs a launchMode of standard or singleTop (new Flutter projects use singleTop). Other values cancel the purchase when Google Play sends the user to another app to verify payment.
  • Android: for Paywalls, MainActivity must extend FlutterFragmentActivity instead of FlutterActivity (details).
Package What it's for When you need it
purchases_flutter Purchases, entitlements, subscription status Always
purchases_ui_flutter Paywalls and Customer Center You show RevenueCat Paywalls or Customer Center
purchases_admob_flutter Tracks AdMob ad events in RevenueCat You show AdMob ads. Install it separately

Quick start

Before you start, create a RevenueCat project, connect your store or start with the Test Store, and add an entitlement. See the Quickstart.

Configure Purchases once at app launch with each platform's public API key (the Test Store key while you test, in debug builds only):

import 'dart:io' show Platform;

import 'package:purchases_flutter/purchases_flutter.dart';

Future<void> initPlatformState() async {
  await Purchases.setLogLevel(LogLevel.debug);

  late PurchasesConfiguration configuration;
  if (Platform.isAndroid) {
    configuration = PurchasesConfiguration(<revenuecat_project_google_api_key>);
  } else if (Platform.isIOS) {
    configuration = PurchasesConfiguration(<revenuecat_project_apple_api_key>);
  }
  await Purchases.configure(configuration);
}

This snippet covers Android and iOS. On macOS, add a Platform.isMacOS branch that uses your Apple API key. On web, check kIsWeb (from package:flutter/foundation.dart) first and pass the public API key of your web config (Flutter web setup).

Inside an async function, check whether the user has an active entitlement before you show a paywall:

import 'package:flutter/services.dart';

try {
  CustomerInfo customerInfo = await Purchases.getCustomerInfo();
  if (customerInfo.entitlements.active.isNotEmpty) {
    // User has access to some entitlement
  }
} on PlatformException catch (e) {
  // Error fetching customer info
}

What's included

  • Paywalls: build single-screen or multi-step paywalls in the dashboard and change them without an app update.
  • Customer Center: a self-service screen where users cancel subscriptions and restore purchases. On iOS, users can also request refunds and change plans.
  • Placements: serve a different Offering at each paywall location in your app.
  • Test Store: make test purchases before you set up App Store Connect or Google Play Console.
  • In-app currency: read the current Customer's in-app currency balances.
  • iOS subscription offers: promotional offers, the offer code redemption sheet, and win-back offers.
  • Your own purchase code: set purchasesAreCompletedBy when your app completes purchases itself, for example with another in-app purchase plugin.
  • Offline entitlements: the SDK grants entitlements for new subscription purchases while RevenueCat's servers are down. It's unavailable when your app completes purchases itself.
  • Trusted Entitlements: informational by default on iOS, Android, and macOS. The SDK checks a signature on entitlement data and reports the result in each entitlement's verification property, so your app can detect tampered responses. It doesn't block access.
  • Flutter web: the SDK uses RevenueCat Billing, Stripe Billing, or Paddle Billing instead of the app stores. Redemption Links unlock a web purchase in your mobile app from a deep link.
  • Ad Monetization: report ad impressions, clicks, and revenue next to subscription data. On iOS, ad tracking needs iOS 15 or later. The AdMob adapter tracks AdMob events automatically.

Documentation

  • Install guide: pub setup, iOS and Android project setup, Flutter web, and troubleshooting.
  • Configure the SDK: API keys for each platform, debug logs, Test Store, and other configuration options.
  • Displaying paywalls: present a paywall with presentPaywall, presentPaywallIfNeeded, or PaywallView.
  • Testing purchases: Test Store and sandbox testing.
  • Migration guide: changes in the current major version, including the Flutter 3.41 and Dart 3.11 minimums and the Swift Package Manager requirement on iOS and macOS.
  • SDK reference: every public class and method in purchases_flutter. purchases_ui_flutter has its own reference.

Using an AI coding agent

Your agent's training data is likely older than the current version of this SDK. Point it at current sources:

  • llms.txt: an index of the docs. Add .md to any docs URL for a Markdown version.
  • RevenueCat MCP server: lets your agent read and change your RevenueCat project configuration.
  • AI Toolkit: installs RevenueCat skills and the MCP server in one step.
  • Releases: check the latest version before adding the dependency.

Sample apps

  • MagicWeather: a Flutter app for iOS, Android, and web that configures the SDK, builds a custom paywall from the current Offering, checks subscription status, restores purchases, and logs users in and out.

Getting help

Contributing

This repository is published from the main branch and release tags of RevenueCat's internal development repository. Issues are tracked here. Pull requests are welcome: a maintainer reviews them here and brings accepted changes into the internal repository, so they can't be merged directly.

See the contributing guide.

License

MIT. See LICENSE.

Libraries

errors
models/ad_capture_method
models/ad_displayed_data
models/ad_failed_to_load_data
models/ad_format
models/ad_loaded_data
models/ad_mediator_name
models/ad_opened_data
models/ad_revenue_data
models/ad_revenue_precision
models/ad_reward_earned_unverified_data
models/ad_reward_prompt_accepted_data
models/ad_reward_prompt_shown_data
models/billing_plan_type
models/custom_paywall_impression_params
models/customer_info_wrapper
models/entitlement_info_wrapper
models/entitlement_infos_wrapper
models/entitlement_verification_mode
models/google_product_change
models/installments_info
models/introductory_price
models/map_helpers
models/offering_wrapper
models/offerings_wrapper
models/package_wrapper
models/period_unit
models/period_wrapper
models/presented_offering_context_wrapper
models/presented_offering_targeting_context_wrapper
models/price_wrapper
models/pricing_phase_wrapper
models/product_category
models/promotional_offer
models/purchase_params
models/purchase_result
models/purchases_completed_by
models/purchases_configuration
models/purchases_error
models/reward_verification_result
models/reward_verification_token
models/rewarded_ad_tracking_metadata
models/store
models/store_product_change
models/store_product_discount
models/store_product_wrapper
models/store_transaction
models/storefront
models/storekit_version
models/subscription_info_wrapper
models/subscription_option_wrapper
models/sync_purchases_result
models/upgrade_info
models/verification_result
models/verified_reward
models/virtual_currencies
models/virtual_currency
models/web_purchase_redemption
models/web_purchase_redemption_result
models/win_back_offer
object_wrappers
purchases_flutter
web/purchases_flutter_web