Aller au contenu principal

Adaptateurs de framework

SDK Dart

Le client pour les applications Flutter et Dart : du Dart pur, sans dépendance à l’exécution, avec les mêmes événements, drapeaux et boîte de réception que les autres clients.

Où il est publié

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

Installation

Bash
dart pub add prodantix_sdk

Exemple

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();
Ce client retient qui l'utilise : identify fixe l'identifiant une seule fois, et chaque appel suivant concerne cette personne. Appelez reset à la déconnexion.

Drapeaux distants et locaux

Une vérification distante interroge le serveur et fait autorité. Une vérification locale évalue dans le processus un instantané mis en cache du jeu de règles, sans aller-retour à chaque appel, ce qu'exige un chemin critique.

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

Où il fonctionne

Il vise le mobile et la machine virtuelle Dart, et atteint le réseau via dart:io. Sur toute autre plateforme, fournissez vos propres Transport et Requester : rien d'autre ne change dans le 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,
);