Skip to main content

purchases_flutter 12.0.0 copy "purchases_flutter: ^12.0.0" to clipboard
purchases_flutter: ^12.0.0 copied to clipboard

Flutter in-app purchases and subscriptions made easy. The plugin supports iOS, macOS and Android.

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.

926
likes
140
points
743k
downloads

Documentation

Documentation
API reference

Publisher

verified publisherrevenuecat.com

Weekly Downloads

Flutter in-app purchases and subscriptions made easy. The plugin supports iOS, macOS and Android.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

equatable, flutter, flutter_web_plugins, web

More

Packages that depend on purchases_flutter

Packages that implement purchases_flutter