メインコンテンツへスキップ

クライアントライブラリ

フレームワークアダプター

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,
);