Skip to main content

Flutter

Instructions for installing Purchases SDK for Flutter

AIAsk AIChatGPTClaude

What is RevenueCat?

RevenueCat provides a backend and SDKs that wrap StoreKit, Google Play Billing, and RevenueCat Web Billing to make implementing in-app and web purchases and subscriptions easy. With our SDK, you can build and manage your app business on any platform without having to maintain IAP infrastructure. You can read more about how RevenueCat fits into your app or you can sign up free to start building.

Requirements

Xcode 13.3.1+ Minimum target: iOS 11.0+

Installation

Release

To use this plugin, add purchases_flutter as a dependency in your pubspec.yaml file (and run an implicit dart pub get):

dependencies:
purchases_flutter: <latest version> // or 9.0.0-beta.3 for Flutter Web

Alternatively run this command:

 $ flutter pub add purchases_flutter

iOS Deployment Target

RevenueCat is compatible with iOS 11.0 or higher. Flutter does not automatically set the iOS deployment target for your project. You need to make sure that the deployment target is set to 11.0 or higher. To do that, simply edit ios/Podfile and add the following line if it's not already there:

platform :ios, '11.0'

Set it to 11.0 or a higher version for RevenueCat to work.

iOS Swift Version

RevenueCat requires Swift >= 5.0 to work. If the Podfile in your project's ios folder specifies a Swift version, make sure that it's at least 5.0, otherwise you may run into build issues.

Set the correct launchMode for Android

Depending on your user's payment method, they may be asked by Google Play to verify their purchase in their (banking) app. This means they will have to background your app and go to another app to verify the purchase. If your Activity's launchMode is set to anything other than standard or singleTop, backgrounding your app can cause the purchase to get cancelled. To avoid this, set the launchMode of your Activity to standard or singleTop in your Android app's android/app/src/main/AndroidManifest.xml file:

<activity 
android:name="com.your.Activity"
android:launchMode="standard" /> <!-- or singleTop -->

You can find Android's documentation on the various launchMode options here.

Optional: Change MainActivity subclass

If you plan to use RevenueCat Paywalls, your MainActivity needs to subclass FlutterFragmentActivity instead of FlutterActivity.

package com.your.package.name

import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity()

Import Purchases

You should now be able to import purchases_flutter.

import 'package:purchases_flutter/purchases_flutter.dart';
📘Enable In-App Purchase capability for iOS projects in Xcode

Don't forget to enable the In-App Purchase capability for your iOS project under Project Target -> Capabilities -> In-App Purchase

📘Include BILLING permission for Android projects

Don't forget to include the BILLING permission in your AndroidManifest.xml file

<uses-permission android:name="com.android.vending.BILLING" />

If you're using other plugins like mobx, you may run into conflicts with types from other plugins having the same name as those defined in purchases_flutter.
If this happens, you can resolve the ambiguity in the types by adding an import alias, for example:

import 'package:purchases_flutter/purchases_flutter.dart' as purchases;

After that, you can reference the types from purchases_flutter as purchases.Foo, like purchases.CustomerInfo.

Flutter Web Configuration

RevenueCat's Flutter SDK supports web platforms, allowing you to manage subscriptions across Flutter web, mobile, and desktop apps using the same SDK.

Web Product Configuration

To enable web purchases in your Flutter app, you'll need to configure products using a RevenueCat Web Billing app.

  1. Create a Web Billing App in your RevenueCat project dashboard
  2. Configure your products for web purchases

For detailed instructions on setting up web products and configuring Web Billing, see the Web Billing Overview.

📘Web Billing vs In-App Purchases

Web Billing is RevenueCat's billing engine for web purchases, which uses Stripe as the payment processor. This is separate from iOS/Android in-app purchases but integrates with the same RevenueCat entitlements system, allowing unified subscription management across platforms.

Current Limitations

When using the Flutter SDK on web, keep in mind the following:

  • Web Billing Required: Web purchases require RevenueCat Web Billing setup. Native iOS/Android in-app purchases cannot be processed through the web platform.
  • Payment Processing: Web Billing purchases use Stripe as the payment processor through RevenueCat Web Billing.
  • Customer Portal: Users can manage their web subscriptions through the RevenueCat-provided customer portal.
  • Platform Separation: Web products must be configured separately from iOS/Android products in the RevenueCat dashboard, though entitlements can be shared across platforms.
  • User Identity: For unified cross-platform subscriptions, ensure you're using the same appUserID across web and mobile platforms.
  • Unsupported operations: There are some unsupported operations. Mainly operations getProducts, purchaseProduct or restorePurchases won't work on web environments.

Next Steps