Lewati ke konten utama

SDK Dart

Klien untuk aplikasi Flutter dan Dart: Dart murni, tanpa dependensi runtime, dengan event, flag, dan kotak masuk yang sama seperti klien lainnya.

Tempat diterbitkan

prodantix_sdk on pub.dev. Pure Dart, with no runtime dependencies.

Instal

Bash
dart pub add prodantix_sdk

Contoh

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();
Klien ini mengingat siapa yang memakainya, jadi identify menetapkan distinct id sekali saja dan setiap panggilan berikutnya adalah tentang orang tersebut. Panggil reset saat keluar.

Flag jarak jauh dan lokal

Pemeriksaan jarak jauh bertanya ke server dan itulah yang otoritatif. Pemeriksaan lokal mengevaluasi snapshot aturan yang tersimpan di cache di dalam proses, tanpa perjalanan bolak-balik tiap panggilan, dan itulah yang dibutuhkan jalur panas.

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>'])) {
  // ...
}

Di mana ia berjalan

Ia menyasar perangkat seluler dan Dart VM, serta menjangkau jaringan lewat dart:io. Di platform lain mana pun, berikan Transport dan Requester milik Anda sendiri; tidak ada lagi yang berubah pada klien.

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