How revenuecat/purchases-flutter works
Purpose and entry points
purchases_flutter is a Flutter plugin exposing RevenueCat subscription, purchase, entitlement, and receipt-status capabilities over native store SDKs and the RevenueCat backend. Its public Dart entry point is lib/purchases_flutter.dart; shared error and domain APIs start at lib/errors.dart and lib/models/. A companion UI package provides native paywall and customer-center views via purchases_ui_flutter/lib/purchases_ui_flutter.dart.
Core Dart API and domain contract
The main package presents a Dart-facing API, configuration, purchase parameters/results, and strongly typed wrappers for native/RevenueCat payloads. Models isolate app consumers from platform-channel map shapes and encode offerings, customer info, products, transactions, subscriptions, virtual currencies, and web redemption.
• lib/purchases_flutter.dart
• lib/models/purchases_configuration.dart
• lib/models/customer_info_wrapper.dart
Flutter-to-native purchase boundary
Dart calls are bridged through the Flutter plugin implementations into RevenueCat’s native SDK integrations. Android registers the plugin in Java; iOS/macOS package native implementations are Objective-C. This boundary owns interaction with Google Play Billing and Apple StoreKit rather than implementing store transactions in Dart.
• android/src/main/java/com/revenuecat/purchases_flutter/PurchasesFlutterPlugin.java
• ios/purchases_flutter/Sources/purchases_flutter/PurchasesFlutterPlugin.m
• macos/purchases_flutter/Sources/purchases_flutter/PurchasesFlutterPlugin.m
Web runtime path
Web is a separate implementation layer, backed by a JavaScript hybrid mapping asset. It adapts the same Dart API to browser-compatible RevenueCat functionality; it is not routed through Android/iOS platform channels.
• lib/web/purchases_flutter_web.dart
• assets/web/purchases_js_hybrid_mappings.js
Purchase and entitlement flow
Application code configures the SDK, identifies/configures a user, retrieves offerings/products, initiates a purchase or restore, then receives typed purchase/customer-info results. Native SDKs communicate with the applicable store and RevenueCat services; RevenueCat performs server-side receipt validation and returns subscription/entitlement state. Dart wrappers deserialize the result boundary for Flutter callers.
• lib/models/offering_wrapper.dart
• lib/models/purchase_params.dart
• lib/models/purchase_result.dart
Native UI package
purchases_ui_flutter is a distinct Flutter plugin layered over the core purchasing SDK. Its Dart widgets/method handlers host platform-native paywall, footer, and customer-center views; Android uses platform view factories/views, while iOS uses Swift native view wrappers. UI results and presentation configuration cross the same plugin boundary.
• purchases_ui_flutter/lib/views/paywall_view.dart
• purchases_ui_flutter/android/src/main/kotlin/com/revenuecat/purchases_ui_flutter/views/PaywallView.kt
• purchases_ui_flutter/ios/purchases_ui_flutter/Sources/purchases_ui_flutter/PurchasesUiPaywallView.swift
Runtimes, delivery, and validation clients
The repository is primarily Dart/Flutter, with Android Gradle/Java/Kotlin and Apple CocoaPods/Swift Package Manager/Objective-C/Swift host integrations. The core package is defined for pub publishing in pubspec.yaml; native package manifests support direct Apple dependency integration. api_tester is a Flutter executable that exercises the exposed API surface, while Maestro runs end-to-end purchase-through-paywall validation against a dedicated test app.
• pubspec.yaml
• api_tester/lib/main.dart
• e2e-tests/maestro/e2e_tests/purchase_through_paywall.yaml
Components 16
Core Flutter SDK
- Public Dart API · Configuration and purchase APIs exposed to apps.
lib/purchases_flutter.dart - Typed domain models · Wraps offerings, customer state, products, and transactions.
lib/models/customer_info_wrapper.dart - Purchase configuration
lib/models/purchases_configuration.dart - Purchase contracts · Parameters and typed purchase outcomes.
lib/models/purchase_result.dart - Web implementation
lib/web/purchases_flutter_web.dart - Hybrid JS mappings
assets/web/purchases_js_hybrid_mappings.js
Native runtimes
- Android plugin bridge · Bridges Dart calls to the Android RevenueCat SDK.
android/src/main/java/com/revenuecat/purchases_flutter/PurchasesFlutterPlugin.java - iOS/macOS plugin bridges · Bridge Dart calls to Apple RevenueCat SDK integrations.
ios/purchases_flutter/Sources/purchases_flutter/PurchasesFlutterPlugin.m - App stores
- RevenueCat services · Validates receipts and returns subscription and entitlement state.
Native UI plugin
- UI Flutter API · Hosts paywall and customer-center presentation APIs.
purchases_ui_flutter/lib/views/paywall_view.dart - Android paywall view
purchases_ui_flutter/android/src/main/kotlin/com/revenuecat/purchases_ui_flutter/views/PaywallView.kt - iOS paywall view
purchases_ui_flutter/ios/purchases_ui_flutter/Sources/purchases_ui_flutter/PurchasesUiPaywallView.swift
Delivery & validation
- Published package
pubspec.yaml - API tester · Exercises the exposed SDK API surface.
api_tester/lib/main.dart - Purchase E2E flow · Validates purchase through native paywall.
e2e-tests/maestro/e2e_tests/purchase_through_paywall.yaml
Connections 19
- Published package → Public Dart API: publishes
- Public Dart API → Purchase configuration: configures
- Public Dart API → Purchase contracts: uses
- Public Dart API → Typed domain models: returns
- Public Dart API → Android plugin bridge: platform channel
- Public Dart API → iOS/macOS plugin bridges: platform channel
- Public Dart API → Web implementation: web runtime
- Web implementation → Hybrid JS mappings: uses
- Android plugin bridge → App stores: purchase operations
- iOS/macOS plugin bridges → App stores: purchase operations
- Android plugin bridge → RevenueCat services: customer and receipt state
- iOS/macOS plugin bridges → RevenueCat services: customer and receipt state
- App stores → RevenueCat services: receipts
- RevenueCat services → Typed domain models: typed state response
- UI Flutter API → Public Dart API: layers on core SDK
- UI Flutter API → Android paywall view: platform view
- UI Flutter API → iOS paywall view: native view
- API tester → Public Dart API: exercises
- Purchase E2E flow → UI Flutter API: validates paywall purchase