SDK Dart
Client cho ứng dụng Flutter và Dart: thuần Dart, không phụ thuộc lúc chạy, với cùng các sự kiện, cờ và hộp thư mà những client khác mang theo.
Nơi phát hành
prodantix_sdk on pub.dev. Pure Dart, with no runtime dependencies.
Cài đặt
Bash
dart pub add prodantix_sdkVí dụ
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();Client này nhớ ai đang dùng nó, nên identify đặt id người dùng một lần và mọi lần gọi sau đều nói về người đó. Hãy gọi reset khi đăng xuất.
Cờ từ xa và cờ cục bộ
Phép kiểm từ xa hỏi máy chủ và mang tính quyết định. Phép kiểm cục bộ đánh giá bản chụp bộ quy tắc đã lưu đệm ngay trong tiến trình, không phải đi về ở mỗi lần gọi, và đó là thứ một đường dẫn nóng cần.
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>'])) {
// ...
}Nơi nó chạy
Nó nhắm tới thiết bị di động và máy ảo Dart, và ra mạng qua dart:io. Trên bất kỳ nền tảng nào khác, hãy truyền vào Transport và Requester của riêng bạn; phần còn lại của client không đổi.
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,
);