Перейти к основному содержимому

Клиентские библиотеки

Адаптеры фреймворков

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 задаёт идентификатор один раз, и каждый последующий вызов относится к этому человеку. При выходе вызывайте 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, а до сети добирается через 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,
);