encore_flutter 1.0.7
encore_flutter: ^1.0.7 copied to clipboard
Flutter plugin wrapping the native Encore iOS and Android SDKs for monetization, offers, and entitlements. All offer UI is rendered natively via StoreKit (iOS) and Play Billing (Android).
Encore Flutter SDK #
Flutter plugin wrapping the native Encore iOS and Android SDKs. All offer UI is rendered natively — this plugin bridges configuration, identity, placement presentation, and callback handling via platform channels.
Installation #
Add to your pubspec.yaml:
dependencies:
encore_flutter: ^1.0.0
iOS #
The EncoreKit CocoaPod is automatically included as a transitive dependency of the Flutter plugin — no manual pod configuration is needed.
Minimum deployment target: iOS 15.0.
Android #
Add the Encore SDK dependency to your android/app/build.gradle.kts:
dependencies {
implementation("com.encorekit:encore:1.4.23")
}
Minimum SDK: 26.
Usage #
Configure #
Call once early in your app lifecycle (e.g., in main() or your root widget's initState):
import 'package:encore_flutter/encore_flutter.dart';
await Encore.shared.configure(
apiKey: 'your_api_key',
logLevel: LogLevel.debug,
);
Register Handlers #
Set up handlers before presenting offers:
Encore.shared.onPurchaseRequest((purchaseRequest) {
// Purchase Request includes:
// purchaseRequest.productId
// purchaseRequest.promoId
// purchaseRequest.placementId
// Trigger purchase via your subscription manager (RevenueCat, etc.)
});
Encore.shared.onPassthrough((placementId) {
// Encore didn't result in a purchase — run your original button logic
});
// Optional: only fires when no onPurchaseRequest handler is set
Encore.shared.onPurchaseComplete((result, productId) {
print('Native purchase completed: ${result.productId}');
});
Identify User #
After authentication:
await Encore.shared.identify(
userId: 'user_123',
attributes: UserAttributes(
email: 'user@example.com',
subscriptionTier: 'premium',
),
);
Update Attributes #
await Encore.shared.setUserAttributes(
UserAttributes(billingCycle: 'annual'),
);
Present Offers #
final result = await Encore.shared.placement('cancel_flow').show();
switch (result) {
case PresentationResultGranted(:final offerId):
print('Offer granted: $offerId');
case PresentationResultNotGranted(:final reason):
print('Not granted: $reason');
}
Reset (Logout) #
await Encore.shared.reset();
Architecture #
Flutter App
│
▼
┌─────────────────────────────┐
│ Encore Dart API │
│ (lib/src/encore.dart) │
├─────────────────────────────┤
│ MethodChannel │
│ com.encorekit/encore │
├──────────────┬──────────────┤
│ iOS Plugin │ Android Plugin│
│ (Swift) │ (Kotlin) │
├──────────────┼──────────────┤
│ Encore │ com.encorekit│
│ .xcframework│ :encore AAR │
└──────────────┴──────────────┘
The Dart layer sends method calls to the native plugins, which delegate to the native Encore SDK singletons. Native-to-Dart callbacks (purchase requests, passthrough) are forwarded via reverse method invocations on the same channel.
API Reference #
| Method | Description |
|---|---|
Encore.shared.configure(apiKey:, logLevel:) |
Initialize the SDK |
Encore.shared.identify(userId:, attributes:) |
Associate user identity |
Encore.shared.setUserAttributes(attributes) |
Merge user attributes |
Encore.shared.reset() |
Clear user data (logout) |
Encore.shared.placement(id).show() |
Present native offer sheet |
Encore.shared.onPurchaseRequest(handler) |
Handle purchase delegation |
Encore.shared.onPurchaseComplete(handler) |
Handle native purchase completion |
Encore.shared.onPassthrough(handler) |
Handle not-granted outcomes |