git:20260331.a8cec9f to git:20260401.b1f912e

4 added, 4 removed. Audit A to A.

What this update changes in the checks

No check changed: every fixed check gives the same answer before and after this update.

A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.

---
- name: "revenuecat-flutter"
- description: "RevenueCat in-app purchase and subscription management for Flutter. Use when implementing paywalls, managing entitlements, handling subscription lifecycle, or integrating StoreKit/Google Play Billing."
+ name: "integrating-revenuecat"
+ description: "Integrates RevenueCat in-app purchases and subscriptions into Flutter apps using `purchases_flutter`. Use when implementing paywalls, checking entitlements via `CustomerInfo`, configuring `PurchasesConfiguration` for iOS or Android, displaying paywalls with `purchases_ui_flutter`, handling purchase errors via `PurchasesErrorHelper`, restoring purchases, integrating RevenueCat with Riverpod or Bloc, presenting the Customer Center, handling web purchase redemption, or calling `Purchases.logIn` for cross-device purchase sync."
metadata:
- last_modified: "2026-03-12 11:18:17 (GMT+8)"
+ last_modified: "2026-04-01 14:35:00 (GMT+8)"
---
# RevenueCat (Flutter) Latest Version Best Practices Guide (v9.13.x)
## Goal
- RevenueCat is the industry standard solution for handling "In-App Purchases (IAP)" and "Subscriptions" in mobile applications. In Flutter, the official package is `purchases_flutter`. The current latest version is roughly **9.13.x**.
+ RevenueCat is the industry-standard solution for handling In-App Purchases (IAP) and subscriptions in mobile applications. In Flutter, the official package is `purchases_flutter` (paired with `purchases_ui_flutter` for pre-built paywall UI).
## Instructions
### 1. Core Concept: Entitlements > Products
In traditional IAP development, developers often focus on "which Product ID the user purchased."
**RevenueCat's best practice is: Always check the user's Entitlements.**
* **Products**: The actual items configured in Apple/Google consoles (e.g., `monthly_sub_199`).
* **Offerings**: RevenueCat packages multiple Products into a display offering (e.g., a default offering contains "Monthly" and "Annual" subscriptions). This makes A/B testing extremely easy, allowing you to swap products without changing the APP code.
* **Entitlements**: The ultimate goal unlocked after a user purchases (e.g., `pro_access`).
๐Ÿ‘‰ **Your APP logic should ALWAYS only check if `pro_access` is active. Do not care about which offering the user bought to get it.**
### 2. Dependencies and Initialization Setup
#### 2.1 Install Packages
```yaml
dependencies:
purchases_flutter: ^9.13.1
# ๐ŸŒŸ Highly Recommended: Use the official native UI checkout templates (Paywalls) to reduce the pain of building your own UI
purchases_ui_flutter: ^9.13.1
```
#### 2.2 Platform Specific Configurations (Extremely Important)
* **Android (`AndroidManifest.xml`)**: Be sure to set the main Activity's `launchMode` to `singleTask` or `singleTop`. Otherwise, unexpected behaviors like canceled purchases might occur when the user switches back from the Google Play payment screen.
* **iOS**: Ensure Xcode 14.0+, and the deployment target is generally recommended to be iOS 13.0+.
#### 2.3 Initialization (On App Startup)
Complete the initialization as early as possible, either in `main()` or before the App UI renders.
```dart
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:purchases_flutter/purchases_flutter.dart';
Future<void> initPlatformState() async {
await Purchases.setLogLevel(kDebugMode ? LogLevel.debug : LogLevel.info);
PurchasesConfiguration? configuration;
if (Platform.isAndroid) {
// Android natively uses a Builder underneath; just provide the API Key in Flutter
configuration = PurchasesConfiguration('goog_api_key_here');
} else if (Platform.isIOS) {
configuration = PurchasesConfiguration('appl_api_key_here')
// ๐ŸŒŸ v7+ Best Practice: Explicitly define StoreKit version (defaults to auto-select, but StoreKit 2 requires In-App Purchase Key configurations in your RevenueCat Dashboard)
..storeKitVersion = StoreKitVersion.storeKit2;
}
if (configuration != null) {
// ๐ŸŒŸ Best Practice: Pass your own user ID here to help RevenueCat sync across devices.
// configuration.appUserID = "my_app_user_id";
// โš ๏ธ Deprecation Notice: "Observer Mode" is now legacy. If your App fundamentally completes its own transactions (instead of RevenueCat), deploy:
// configuration.purchasesAreCompletedBy = PurchasesAreCompletedByMyApp(storeKitVersion: StoreKitVersion.storeKit2);
await Purchases.configure(configuration);
}
}
```
> [!WARNING]
> **Google Play Billing 8 Limitations (SDK v8/v9+)**: The latest Android underlying libraries completely eradicated APIs querying for expired subscriptions and *consumed* one-time products.
>
> **CRITICAL**: If your App offers "Lifetime Unlock" products without a backend account system, you **MUST** strictly configure them as **Non-consumable** inside the RevenueCat dashboard. If labeled as consumable, RevenueCat consumes them instantly, and users will permanently lose the ability to `restorePurchases`!
### 3. Checking Entitlements and State Management (Best Practices)
Integrate RevenueCat's state into your state management (like Riverpod / Bloc) to drive UI unlocking.
```dart
// Using Riverpod as an example
final customerInfoProvider = FutureProvider<CustomerInfo>((ref) async {
// Get the latest state
return await Purchases.getCustomerInfo();
});
final isProUserProvider = Provider<bool>((ref) {
final customerInfo = ref.watch(customerInfoProvider).valueOrNull;
if (customerInfo == null) return false;
// ๐ŸŒŸ Best Practice: Only verify if the entitlement is active
return customerInfo.entitlements.all['pro_access']?.isActive == true;
});
```
Besides the initial fetch, it's recommended to listen for customer info changes (e.g., successful background renewals):
```dart
Purchases.addCustomerInfoUpdateListener((customerInfo) {
// Update your global state (e.g., notify Bloc or invalidate Riverpod provider)
// ref.invalidate(customerInfoProvider);
});
```
### 4. Checkout and Displaying the Paywall
RevenueCat's strength lies in its ability to let you remotely control what to sell.
#### 4.1 Using the Official Paywall (Fastest, Most Stable)
Through `purchases_ui_flutter`, you can directly summon the paywall designed in the RevenueCat console, saving you the time of building the UI.
```dart
import 'package:purchases_ui_flutter/purchases_ui_flutter.dart';
Future<void> showPaywall(BuildContext context) async {
// Presents a full-screen Paywall meticulously designed in the RevenueCat Dashboard
final paywallResult = await RevenueCatUI.presentPaywall();
if (paywallResult == PaywallResult.purchased) {
// Purchase successful, update state and close the wall
}
}
```
#### 4.2 Customer Center (v9+ New Feature)
RevenueCatUI now encompasses a full-fledged robust **Customer Center** interface natively empowering users to manage subscriptions, cancel, or seek refunds autonomously without developers coding management screens.
```dart
// Launch the autonomous subscription management center directly
await RevenueCatUI.presentCustomerCenter();
```
#### 4.3 Custom Paywall
If you need complete customization, fetch the `Offerings` and manually call the purchase method:
```dart
Future<void> purchasePackage(Package package) async {
try {
// Execute purchase. โš ๏ธ v9 Breaking Change: Now returns `PurchaseResult` encapsulating `customerInfo` and `storeTransaction` instead of exposing `CustomerInfo` directly.
PurchaseResult result = await Purchases.purchasePackage(package);
// ๐ŸŒŸ Principle: Still check the Entitlement after purchase leveraging the extracted customerInfo!
final isPro = result.customerInfo.entitlements.all['pro_access']?.isActive == true;
if (isPro) {
// Successfully unlocked!
}
} on PlatformException catch (e) {
// ๐ŸŒŸ Officially endorsed error interception approach
var errorCode = PurchasesErrorHelper.getErrorCode(e);
if (errorCode != PurchasesErrorCode.purchaseCancelledError) {
// Show error to the user
}
}
}
```
#### 4.4 Web Redemption (Flutter Web)
RevenueCat v9 integrates Web Billing smoothly. You must parse `WebPurchaseRedemptionResult` exhaustively through `switch`:
```dart
switch (result) {
case WebPurchaseRedemptionSuccess(:final customerInfo):
// Redeemed successfully
break;
case WebPurchaseRedemptionError(:final error):
// Redemption failed
break;
case WebPurchaseRedemptionPurchaseBelongsToOtherUser():
// Already tied to another user
break;
case WebPurchaseRedemptionInvalidToken():
case WebPurchaseRedemptionExpired(:final obfuscatedEmail):
// Validation failures
break;
};
```
### 5. Restore Purchases
Apple mandates that Apps must provide a "Restore Purchases" button.
```dart
try {
CustomerInfo customerInfo = await Purchases.restorePurchases();
// Check entitlements as usual
if (customerInfo.entitlements.all['pro_access']?.isActive == true) {
// Restore successful
}
} catch (e) {
// Handle error
}
```
### 6. Summary
1. **Abandon local receipt validation**: Hand this over 100% to RevenueCat.
2. **Decouple logic from products**: In your code, only check `entitlements` through `CustomerInfo`. Do not hardcode any product IDs.
3. **Login Integration**: If your App has its own account system, remember to call `Purchases.logIn(userId)` after login to ensure cross-device purchase history can be bound to your account.
## Constraints
* Always check `entitlements.all['your_entitlement']?.isActive` instead of checking the presence of active subscriptions or product IDs.
* Ensure you configure the `Purchases` singleton before making any other RevenueCat calls.