Flutter
Native Flutter SDK for Dart mobile apps.
Overview
The Flutter SDK provides realtime flag updates, polling fallback, identity targeting, and telemetry through the singleton Flags.
Get started
Install
YYAML
# pubspec.yamldependencies: truflag_flutter: path: <path-to-repo>/sdk/native/flutter/truflag_flutterConfigure
apiKey is required. If no user is passed, the SDK starts anonymous automatically.
DDART
import "package:truflag_flutter/truflag_flutter.dart"; await Flags.configure( apiKey: const String.fromEnvironment("TRUFLAG_CLIENT_KEY"), userId: "user-123", userAttributes: { "plan": "pro", "country": "US", },);SDK API overview
Full configure surface for Flutter.
DDART
Future<void> configure({ required String apiKey, TruflagUser? user, String? userId, Map<String, dynamic>? userAttributes, TruflagStorage? storage, String baseUrl = "https://sdk.truflag.com", String streamUrl = "wss://stream.sdk.truflag.com", bool streamEnabled = true, TruflagLogLevel logLevel = TruflagLogLevel.debug, TruflagLogger? logger, TruflagFetchFn? fetchFn, int cacheTtlMs = 300000, int pollingIntervalMs = 60000, int requestTimeoutMs = 6000, bool telemetryEnabled = true, int telemetryFlushIntervalMs = 10000, int telemetryBatchSize = 50,});Identity
DDART
await Flags.login( userId: "user-456", attributes: {"plan": "enterprise"},); await Flags.setAttributes({ "plan": "enterprise", "region": "us-east-1",}); await Flags.logout(); // switches to anonymous user and refreshesFlag reads
Use one read method: getFlag(key, fallback).
DDART
final enabled = Flags.getFlag("my-flag", false);final variant = Flags.getFlag("checkout-variant", "control");final config = Flags.getFlag("checkout-config", <String, dynamic>{}); final payload = Flags.getFlagPayload("my-flag");Events
DDART
await Flags.track( "checkout_completed", properties: { "source": "flutter", "value": 99.95, "context": {"screen": "checkout"}, "items": ["sku_1", "sku_2"], },); await Flags.expose("my-flag");Reactive updates
watch() emits when flags/identity/diagnostics change, including websocket-driven updates.
DDART
final sub = Flags.watch().listen((snapshot) { final next = Flags.getFlag("my-flag", false); // update UI state here}); // Later:await sub.cancel();Troubleshooting
Flags always return fallback
Confirm Flags.isReady is true and the flag key exists in the environment tied to your apiKey.
No realtime updates
Verify streamEnabled: true and a validstreamUrl. Polling fallback remains active if stream connectivity drops.