In-App Subscriptions in Flutter with RevenueCat
In the world of mobile app development, in-app purchases and subscriptions are essential for generating revenue. However, building and…
In-App Subscriptions in Flutter with RevenueCat
In the world of mobile app development, in-app purchases and subscriptions are essential for generating revenue. However, building and managing this system yourself can be complex, especially when you need to support both iOS and Android with their different billing systems. RevenueCat simplifies this by acting as a cross-platform backend that manages all the heavy lifting for you, from purchase validation to subscription tracking
In this tutorial, you’ll learn how to integrate RevenueCat into your Flutter app. By the end, you’ll have a fully functional subscription flow, allowing you to focus on building features for your users.
What is RevenueCat and Why Use It?
RevenueCat is a platform that provides a unified backend and Software Development Kit (SDK) for managing in-app purchases and subscriptions. It wraps around the native StoreKit (iOS) and Google Play Billing (Android) APIs, offering you a single, consistent interface to work with
Here’s why it’s a game-changer for Flutter developers:
- Simplified Code: You write one set of code for purchases that works on both platforms.
- Centralized Management: Manage products, pricing, and user entitlements from a single web dashboard without needing to push app updates
- Robust Infrastructure: It handles receipt validation, subscription status tracking, and webhook integrations, saving you from building and maintaining your own server logic
- Real-time Analytics: Get insights into key metrics like revenue, churn, and customer lifetime value directly in the dashboard
Before You Start: Prerequisites
- A Flutter development environment set up on your machine.
- An iOS developer account (for App Store Connect) and/or a Google Play Console account.
- A RevenueCat account (you can start for free).
Step 1: Project Setup in the RevenueCat Dashboard
Your journey begins in the RevenueCat dashboard. This is where you’ll define the digital products your app will sell.
- Create a Project: After signing up, create a new project (e.g., “MyFlutterApp”).
- Define an Entitlement: Entitlements are central to RevenueCat. They represent a level of access or features a user unlocks (e.g., “premium”). You check for this entitlement in your code, not specific product IDs. This allows you to change the products on the backend without updating your app
- Go to Product Setup > Entitlements and click + New.
- Enter an identifier like premium and a description.
3. Connect Your Apps: You need to connect your iOS and Android store apps.
- Go to Apps and click Add an app.
- For iOS, you’ll need your App’s Bundle ID and the App-Specific Shared Secret from App Store Connect
For Android, you’ll need your Google Play Package name and must generate and upload a Service Account Credentials JSON file from Google Cloud
Once configured, RevenueCat will generate a unique Public API Key for each platform. You’ll need these later
Step 2: Adding and Configuring the Flutter SDK
With your dashboard configured, you can now integrate the SDK into your Flutter app.
- Add the Dependencies: Add the purchases_flutter package to your pubspec.yaml file. For a complete paywall UI solution, you can also add purchase_ui_flutter
yaml
dependencies:
purchases_flutter: ^8.8.1
# Optional: For pre-built paywall UIs
purchase_ui_flutter: ^8.8.1
Run flutter pub get.
Platform-Specific Configuration:
- iOS: Ensure your app’s iOS deployment target is set to 11.0 or higher in your ios/Podfile (platform :ios, ‘11.0’). Also, enable the In-App Purchase capability in Xcode
Android: Add the BILLING permission to your AndroidManifest.xml file. Also, ensure your main Activity’s launchMode is set to standard or singleTop to prevent purchase flow issues
<uses-permission android:name=”com.android.vending.BILLING” />
Step 3: Initializing RevenueCat in Your App
Initialize the SDK as early as possible in your app’s lifecycle, typically in main() or your root widget’s initState.
- Import and Configure: Use the public API key from your RevenueCat dashboard. It’s recommended to use a debug log level during development
dart
import 'package:purchases_flutter/purchases_flutter.dart';
Future<void> initRevenueCat() async {
await Purchases.setLogLevel(LogLevel.debug); // For development only
PurchasesConfiguration configuration;
if (Platform.isIOS) {
configuration = PurchasesConfiguration('your_ios_public_api_key');
} else {
configuration = PurchasesConfiguration('your_android_public_api_key');
}
await Purchases.configure(configuration);
}
// Call this in main() before runApp()
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initRevenueCat();
runApp(const MyApp());
}
Step 4: Creating Products and Fetching Offerings
Products (like “Monthly Plan”) are created in App Store Connect and Google Play Console and then linked inside RevenueCat. They are presented to users through Offerings.
- Create Products in Store Consoles:
- In App Store Connect, create a new subscription with a unique Product ID (e.g., premium_monthly).
- In Google Play Console, create an in-app product with the same ID under the Subscriptions section
2. Link Products and Create an Offering in RevenueCat:
- In RevenueCat, go to Product Catalog > Products and use the “Import” feature to bring in the products you created.
- Attach these products to the premium entitlement you created earlier.
- Go to Offerings and create a new offering (e.g., default). Here, you can group your monthly and yearly products into packages
3. Fetch Offerings in Your App: You can now fetch the current offering to display available packages to the user.
dart
Future<Offering?> fetchCurrentOffering() async {
try {
final offerings = await Purchases.getOfferings();
final currentOffering = offerings.current;
return currentOffering; // This contains the packages for sale
} on PlatformException catch (e) {
// Handle error
return null;
}
}
Step 5: Implementing the Purchase Flow and Checking Entitlements
This is the core user interaction: displaying products, handling purchases, and unlocking features.
- Make a Purchase: Trigger this when a user selects a package. dart
Future<void> makePurchase(Package package) async {
try {
CustomerInfo customerInfo = await Purchases.purchasePackage(package);
// Check the entitlement to unlock features
await handlePurchaseResult(customerInfo);
} on PlatformException catch (e) {
// Handle purchase error (e.g., user cancelled)
if (e.code != PurchasesErrorCode.purchaseCancelledError) {
// Show error message
}
}
}
Check for Active Entitlements: After a purchase or on app start, check the user’s CustomerInfo to see if they have access.
dart
Future<void> handlePurchaseResult(CustomerInfo customerInfo) async {
// Check if the user now has the "premium" entitlement
final entitlement = customerInfo.entitlements.all['premium'];
if (entitlement != null && entitlement.isActive) {
// User is premium! Unlock features, hide ads, etc.
print('User is subscribed!');
} else {
// User does not have active premium access
print('User is not subscribed.');
}
}
// Call this on app startup to restore access
Future<void> loadCustomerStatus() async {
CustomerInfo customerInfo = await Purchases.getCustomerInfo();
await handlePurchaseResult(customerInfo);
}
Restore Purchases: Always provide a way for users to restore their previous purchases, especially when they switch devices
dart
Future<void> restorePurchases() async {
try {
CustomerInfo customerInfo = await Purchases.restorePurchases();
await handlePurchaseResult(customerInfo);
// Show a confirmation dialog to the user
} on PlatformException catch (e) {
// Handle restore error
}
}
Step 6: Testing Your Implementation
Never test purchases with real money. Always use the sandbox environments.
Platform
Test Method (iOS) > Use Sandbox Testers in App Store Connect. Sign into the Sandbox account in your device’s Settings > App Store
Key Consideration:
Sandbox subscriptions auto-renew on an accelerated schedule (e.g., every 5 minutes) for testing
Android
Use License Testers in Google Play Console. Add your test email accounts, then use them on your device
Your app must be published to a closed testing track in Google Play for products to be fetchable
Pro Tip: Enable Sandbox data in the RevenueCat dashboard’s top-right corner to see your test purchases and renewals flow in
Common Pitfalls and Best Practices
- Use Entitlements, Not Product IDs: Always gate features based on the entitlement (e.g., premium), not a specific product ID. This gives you maximum flexibility
Handle Edge Cases: Network issues, cancellations, and pending transactions happen. Ensure your UI responds gracefully and provides clear feedback.
Server-to-Server Notifications: For reliable subscription status updates (like cancellations or renewals), configure App Store Server Notifications and Google Play Real-time Developer Notifications to be sent to RevenueCat
Web Support Note: As of early 2025, Flutter Web support for RevenueCat is in beta. For production web apps, consider this a limiting factor
Final Checklist Before Going Live
- All products are Approved in App Store Connect and Active in Google Play.
- Products are correctly linked to entitlements in the RevenueCat dashboard.
- Server notifications are configured for both iOS and Android.
- You have a working “Restore Purchases” button in your app.
- You have tested the complete flow on both a real iOS device and a real Android device.
- You have switched from sandbox to production API keys in your app’s release build.
Integrating RevenueCat transforms the complex task of managing in-app subscriptions into a streamlined process. By following this guide, you’ve set up a robust system that not only works across platforms today but is also easy to maintain and iterate on in the future. Now, go ahead and build that premium experience your users will love!
Read More: AI-Assisted Programmer: 10 Issues You Will Face (And What to Do About Them)

메타데이터
- post_id
- 75ea5dcf44ee
- slug
- in-app-subscriptions-in-flutter-with-revenuecat-75ea5dcf44ee
- url
- https://medium.com/@mumin-ahmod/in-app-subscriptions-in-flutter-with-revenuecat-75ea5dcf44ee
- canonical_url
- https://medium.com/@mumin-ahmod/in-app-subscriptions-in-flutter-with-revenuecat-75ea5dcf44ee
- author_url
- https://medium.com/@mumin-ahmod
- status
- ok
- fetched_at
- 2026-07-22 19:35:20