Rovenue SDKBeta
Platforms

Flutter

Install and wire the Rovenue SDK in a Flutter app.

Install the package

Add the app-facing package to your pubspec.yaml:

dependencies:
  rovenue_flutter: ^0.33.0

Then fetch it:

flutter pub get

rovenue_flutter is a federated plugin — rovenue_flutter_ios and rovenue_flutter_android are pulled in automatically as platform implementations and wrap the same Swift and Kotlin SDKs (and the shared Rust core, librovenue) that back the native iOS and Android SDKs. Android needs no further setup in most apps.

Android: rovenue_flutter_android adds maven.broverse.ai (where io.rovenue:sdk 0.29.0 and later lives) as a project repository. If your app's android/settings.gradle sets dependencyResolutionManagement with repositoriesMode PREFER_SETTINGS or FAIL_ON_PROJECT_REPOS, that repository is ignored or refused — add the same line to dependencyResolutionManagement.repositories there: maven { url 'https://maven.broverse.ai'; content { includeGroup 'io.rovenue' } }.

iOS needs nothing extra. rovenue_flutter_ios is a Swift package that depends on the Rovenue Swift SDK (github.com/broverse/rovenue-ios) at its own version, so with Swift Package Manager on — the Flutter default — flutter build ios resolves it with no Podfile at all. If your app has Swift Package Manager turned off, the plugin's podspec downloads that same release during pod install instead. Either way there is no Rovenue CocoaPod and nothing to add to your Podfile.

The one requirement is the SDK's platform floor: the app's iOS deployment target must be 16.0 or later. flutter create starts at 15.0, so raise it once in Xcode (Runner → General → Minimum Deployments).

Configure the SDK

Call Rovenue.instance.configure once, before any other SDK method — the earliest point in main() is the right place:

import 'package:flutter/material.dart';
import 'package:rovenue_flutter/rovenue_flutter.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Rovenue.instance.configure(
    apiKey: 'rov_pk_test_FjVJczKFPhknOcx141VbIl0EiRsQ',
  );
  runApp(const MyApp());
}

Self-hosting? baseUrl is optional and defaults to the hosted endpoint https://api.rovenue.io. Override it to point at your own deployment, e.g. Rovenue.instance.configure(apiKey: 'rov_pk_test_FjVJczKFPhknOcx141VbIl0EiRsQ', baseUrl: 'https://api.acme.com'). The host must use https:// — plain http:// is accepted only for localhost during local development.

Types on this page

Future<void> configure({
  required String apiKey,      // public SDK key — rov_pk_live_… or rov_pk_test_…
  String? baseUrl,             // optional — defaults to https://api.rovenue.io
  RovenueLogLevel logLevel = RovenueLogLevel.warn,
  String? appVersion,          // override auto-detected version
  String? environment,
});
FieldTypeDescription
apiKeyStringPublic SDK key from your Rovenue dashboard. Prefix rov_pk_live_ (Production) or rov_pk_test_ (Sandbox).
baseUrlString?Optional. Defaults to https://api.rovenue.io. Override only when self-hosting (https://; http:// allowed for localhost only).
logLevelRovenueLogLevelVerbosity of SDK logs (off/error/warn/info/debug/trace). Defaults to warn.
appVersionString?Overrides the version auto-read from the app bundle.
environmentString?Optional environment label forwarded with requests.

App lifecycle

The SDK observes the app lifecycle itself (the native iOS and Android SDKs underneath watch the app) — there is no foreground/background wiring to add. Reserve Rovenue.instance.shutdown() for full app teardown — never call it on a background transition.


Identifying users

Anonymous subscribers get a permanent id automatically. Call identify once your own auth flow completes, to link that install to your backend user:

// Your backend mints identityToken for this user with the secret key
// (POST /v1/identity-tokens):
await Rovenue.instance.identify('user_123', identityToken);

// When your user signs out:
await Rovenue.instance.logOut();

Unlike the iOS and Android examples, packages/sdk-flutter/example does not call identify() — it demonstrates the anonymous-subscriber path only. The method exists and works identically on Flutter; add this step if your app has its own auth. See Identifying Users for the full identity model.


Entitlements

final pro = await Rovenue.instance.entitlement('pro');
if (pro?.active ?? false) {
  // unlock the feature
}

final all = await Rovenue.instance.entitlementsAll();
// Entitlement
class Entitlement {
  final String id;
  final bool active;
  final String? expiresAt;   // ISO 8601 — absent for non-expiring grants
  final String? productId;
}

Listen for server-pushed updates with Rovenue.instance.changes and re-read on any event:

final sub = Rovenue.instance.changes.listen((event) {
  // event.kind: entitlementsChanged | identityChanged |
  //             virtualCurrenciesChanged | remoteConfigChanged
  Rovenue.instance.entitlementsAll().then((updated) {
    // update your local state with `updated`
  });
});

// Cancel on teardown:
await sub.cancel();

entitlementsAll() is a local cache read — never call refreshEntitlements() from inside this listener. refreshEntitlements() hits the network and, on success, re-emits entitlementsChanged itself, which would re-invoke this same listener forever.

See Entitlements and Reacting to Changes for the full guides.


Offerings & purchases

Use getOfferings() to fetch products configured in your Rovenue dashboard, then purchase(product) to drive the full purchase flow. The SDK triggers the native StoreKit 2 / Play Billing sheet, validates the receipt server-side, and resolves with updated entitlements and virtual-currency balances. On Android the SDK acknowledges or consumes the Play purchase on the device after the server verified it, and purchase resolves even when Play cannot take that acknowledgement yet — see Who acknowledges a Play purchase.

import 'package:rovenue_flutter/rovenue_flutter.dart';

final offerings = await Rovenue.instance.getOfferings();
final products = <StoreProduct>[
  for (final offering in offerings.offerings)
    for (final package in offering.packages) package.product,
];

if (products.isNotEmpty) {
  try {
    final result = await Rovenue.instance.purchase(products.first);
    // result.entitlements and result.virtualCurrencies are already up to date
  } on RovenueException catch (e) {
    if (e.kind == RovenueErrorKind.purchaseCanceled) {
      // User dismissed the store sheet — no action needed
    } else {
      rethrow;
    }
  }
}

To re-validate all prior transactions (e.g. after a reinstall):

await Rovenue.instance.restorePurchases();

restorePurchases() throws a RovenueException when a receipt could not be submitted and no entitlement is active afterwards: retryable is true when trying again can help (offline, timeout, rate limit, 5xx, store unreachable), otherwise it carries the server's refusal, for example serverCode 'RECEIPT_IN_USE' when another account holds the purchase. It no longer returns an empty result in that case. On Android, a second purchase while the Play sheet is up throws RovenueErrorKind.storeProblem. See When a restore fails for what to show in each case.

purchase also accepts an optional Android SubscriptionOption for base-plan/offer selection: Rovenue.instance.purchase(product, option: option).

See Processing Purchases for the full API reference including all error kinds and the StoreProduct shape.


Funnels

Placements serve native funnels, drawn by RovenueFunnelView (see Placements). There is no Dart getFunnel — the platform side resolves the placement itself:

import 'package:rovenue_flutter/rovenue_flutter.dart';

final onboarding = RovenueFunnelView(placementIdentifier: 'onboarding_end');

Purchase attribution is automatic: the funnel's presentedContext is attached to the next purchase() for you.

iOS: declare the languages your app supports

On iOS the funnel draws in the device's language only if your app declares that language: iOS hands an app Locale.current from its declared localizations, so an app that declares only English reaches the SDK as en_XX (en_TR on a Turkish device) and shows the funnel's English copy. Add CFBundleLocalizations (for example en, tr) to ios/Runner/Info.plist, or add the localizations to the Runner project in Xcode. Android needs nothing.


Funnel attribution

Resolve a funnel token from a deep link, an explicit install claim, or — on iOS — the clipboard:

import 'package:rovenue_flutter/rovenue_flutter.dart';

const incomingUrl = '<the URL that opened the app>';

// From a deep link / Universal Link handler:
final claim = await Rovenue.instance.claimFromUrl(incomingUrl);

// Or resolve one explicitly:
final installClaim = await Rovenue.instance.claimInstall();
// iOS only — always resolves null on Android (see the callout below):
final pastedClaim = await Rovenue.instance.claimFromClipboard();
await Rovenue.instance.claimViaEmail('user@example.com');

if (claim != null) {
  // claim.subscriberId, claim.funnelAnswersJson (JSON-encoded object),
  // claim.funnelPreselectedJson (JSON-encoded array of preselected keys)
}

Claims resolved asynchronously on the native side (a deferred deep link or a clipboard token picked up after configure) arrive on the funnelClaims stream, which replays the most recent claim to a new listener:

final sub = Rovenue.instance.funnelClaims.listen((claim) {
  // handle claim.subscriberId / claim.funnelAnswersJson
});

claimFromClipboard is an iOS-only path. On Android it always resolves null without reading the clipboard — Android's deferred-attribution source is the Play Install Referrer, which claimInstall reads for you. The method exists on both platforms so shared code needs no branching, but only claimInstall can recover a deferred Android claim.

Flutter's funnel claim is single-shot: claimFromUrl/claimInstall/claimFromClipboard each make one resolution attempt and return (or throw). The React Native SDK's resolveFunnelClaim additionally chains a retry/fallback sequence across multiple claim sources — that chain has not been ported to Flutter. Callers that need the same fallback behavior should compose it themselves from the primitives above.


Error handling

Every public method throws RovenueException — never a raw PlatformException:

import 'package:rovenue_flutter/rovenue_flutter.dart';

try {
  await Rovenue.instance.identify('user_123', identityToken);
} on RovenueException catch (e) {
  switch (e.kind) {
    case RovenueErrorKind.networkUnavailable:
    case RovenueErrorKind.timeout:
      // e.retryable is true for these — safe to retry
      break;
    case RovenueErrorKind.invalidApiKey:
    case RovenueErrorKind.forbidden:
      // configuration problem — do not retry
      break;
    default:
      print('Rovenue error: ${e.kind.name} — ${e.detail}');
  }
}
class RovenueException implements Exception {
  final RovenueErrorKind kind;
  final String detail;       // always non-null
  final String? serverCode;  // present for API-originated errors
  final int? httpStatus;     // present for API-originated errors
  final bool retryable;
}
FieldTypeDescription
kindRovenueErrorKindNormalized error category, shared across every Rovenue SDK façade.
detailStringHuman-readable message. Falls back to the kind's name when the native side sent none.
serverCodeString?Server-issued error code, when the error came from an API response.
httpStatusint?HTTP status code, when the error came from an API response.
retryableboolWhether the operation is safe to retry.

Feature parity with React Native

Flutter tracks the React Native SDK as its parity bar. As of this release:

AreaStatus
Configure, identity, entitlements, virtual currenciesFull parity
Offerings, purchase, restore, subscription optionsFull parity
Remote config, experimentsFull parity
setFallbackPlacementsFull parity
Funnel token extraction (extractFunnelToken), claimFromUrl/claimInstall/claimViaEmail/claimFromClipboardFull parity
resolveFunnelClaim retry/fallback chainNot ported — see Funnel attribution above

Funnels

The widget hosts the native renderer as a platform view — there is no Dart getFunnel (packages/sdk-flutter/rovenue_flutter/lib/src/funnel_view.dart:10-14) — full path: Show a funnel.

RovenueFunnelView buildOnboardingFunnel() {
  return const RovenueFunnelView(placementIdentifier: 'onboarding');
}

What's next

On this page