본문으로 건너뛰기

클라이언트 라이브러리

프레임워크 어댑터

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