feat_openfeature 0.1.0
feat_openfeature: ^0.1.0 copied to clipboard
OpenFeature provider for feat. Wraps the feat Dart SDK to expose feat through the OpenFeature API.
example/feat_openfeature_example.dart
// Example: read a feat flag through the OpenFeature server API.
//
// Run from the package root with:
// dart run example/feat_openfeature_example.dart
//
// Replace the apiKey with a real feat client-side id (prefix `feat_cs_`) or a
// mobile key. Never use a server key in a client SDK.
import 'package:feat_openfeature/feat_openfeature.dart';
import 'package:feat_sdk/feat_sdk.dart';
import 'package:openfeature_dart_server_sdk/open_feature_api.dart';
Future<void> main() async {
// 1. Construct and initialize the feat client.
final featClient = await FeatClient.initialize(
FeatClientConfig(
apiKey: 'feat_cs_replace_me',
// baseUrl defaults to https://data-01.feat.so
context: EvalContext.user('user-123', attributes: {'plan': 'pro'}),
),
);
// 2. Register the provider with OpenFeature and wait for it to be ready.
final provider = FeatProvider(featClient);
final api = OpenFeatureAPI();
await api.setProviderAndWait(provider);
// 3. Read flags through the standard OpenFeature client.
final client = api.getClient('example');
final checkoutV2 =
await client.getBooleanFlag('checkout-v2', defaultValue: false);
print('checkout-v2 = $checkoutV2');
final theme = await client.getStringFlag('theme', defaultValue: 'light');
print('theme = $theme');
// 4. Change context: set it on the provider (or the feat client) rather than
// via the per-evaluation context argument. This re-polls feat and
// refreshes the synchronous cache.
await provider.setContext(EvalContext.user('user-456'));
// 5. Tear down.
await api.shutdownProvider();
}