Skip to main content

Dart SDK

The client for Flutter and Dart apps: pure Dart, no runtime dependencies, and the same events, flags and inbox the other clients carry.

Where it is published

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

Install

Bash
dart pub add prodantix_sdk

Example

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();
This client remembers who is using it, so identify sets the distinct id once and every later call is about that person. Call reset on sign-out.

Remote and local flags

A remote check asks the server and is authoritative. A local check evaluates a cached snapshot of the ruleset in process, with no round trip per call, which is what a hot path wants.

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

Where it runs

It targets mobile and the Dart VM, and reaches the network through dart:io. On any other platform, pass in your own Transport and Requester; nothing else about the client changes.

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