Lumaktaw sa pangunahing nilalaman

Mga framework adapter

Dart SDK

Ang client para sa mga app na Flutter at Dart: purong Dart, walang runtime dependency, at ang parehong mga event, flag, at inbox na dala ng ibang client.

Saan ito nakalathala

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

I-install

Bash
dart pub add prodantix_sdk

Halimbawa

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();
Naaalala ng client na ito kung sino ang gumagamit nito, kaya isang beses lang itinatakda ng identify ang distinct id at tungkol na sa taong iyon ang bawat susunod na tawag. Tawagin ang reset kapag nag-sign out.

Mga remote at lokal na flag

Ang remote na tsek ay nagtatanong sa server at ito ang may bisa. Ang lokal na tsek ay sinusuri ang naka-cache na snapshot ng ruleset sa loob mismo ng proseso, walang round trip kada tawag, at iyon ang kailangan ng isang hot path.

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

Saan ito tumatakbo

Nakatuon ito sa mobile at sa Dart VM, at umaabot sa network sa pamamagitan ng dart:io. Sa alinmang ibang platform, ipasa ang sarili mong Transport at Requester; wala nang ibang nagbabago sa client.

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