Dart SDK
面向 Flutter 与 Dart 应用的客户端:纯 Dart 实现,没有运行时依赖,提供与其他客户端相同的事件、功能开关和收件箱。
发布位置
prodantix_sdk on pub.dev. Pure Dart, with no runtime dependencies.
安装
Bash
dart pub add prodantix_sdk示例
Dart
import 'package:prodantix_sdk/prodantix_sdk.dart';
const projectKey = String.fromEnvironment('PRODANTIX_PUBLIC_KEY');
final client = ProdantixClient(
apiKey: projectKey,
host: 'https://eu.api.prodantix.com',
);
client.identify('user-123');
client.capture('order.completed', properties: {'total': 42});
final inbox = await client.getInbox();
await client.shutdown();这个客户端会记住是谁在使用它,因此 identify 只设置一次用户 id,之后的每次调用都关于那个人。退出登录时请调用 reset。
远程与本地开关
远程判断向服务端提问,结果具有权威性。本地判断则在进程内对缓存的规则快照求值,每次调用都不必往返,这正是热路径所需要的。
Dart
// Remote: asks the server, and is the authoritative answer.
if (await client.isFeatureEnabled('new-checkout')) {
// ...
}
// Local: evaluated in process from a cached snapshot, no round trip per call.
if (await client.isFeatureEnabledLocal('new-checkout', properties: {'plan': 'pro'})) {
// ...
}
// Every per-flag read records one $feature_flag_called exposure.
final variant = await client.getVariant('new-checkout');
if (variant?['key'] == 'treatment') {
// ...
}
// A flag targeting a cohort reads this user's memberships from the store;
// pass them yourself to skip the lookup.
if (await client.isFeatureEnabledLocal('members', cohorts: ['<cohort id>'])) {
// ...
}它在哪里运行
它面向移动端和 Dart VM,通过 dart:io 访问网络。在其他任何平台上,传入你自己的 Transport 和 Requester 即可,客户端的其余部分毫无变化。
Dart
final client = ProdantixClient(
apiKey: projectKey,
host: 'https://eu.api.prodantix.com',
transport: MyTransport(),
requester: myRequester,
// Hold a Socket.IO subscription to flag changes and refetch the snapshot on
// push, instead of waiting for the 30s poll.
streamFlags: true,
);