Skip to main content

Initialization

The Eppo SDK for Dart and Flutter is easy to initialize while offering robust customization options, making it adaptable to various use cases such as custom caching requirements and ultra-low-latency initialization.

We seek to maintain broad compatibility with Dart and Flutter versions, requiring only a minimum version of Dart 3.0.

Initialize the SDK

To complete basic initialization, you only need to provide an SDK key. Create an SDK key if you don't already have one.

Add the Eppo Dart SDK to your pubspec.yaml file:

dependencies:
eppo: ^1.0.0

Then, initialize the SDK:

import 'package:eppo/eppo.dart';

// Create subject evaluation
final subjectEvaluation = SubjectEvaluation(
subject: Subject(
subjectKey: 'user-identifier'
)
);

// Create client configuration
final clientConfiguration = ClientConfiguration(
sdkPlatform: SdkPlatform.dart,
);

// Initialize the SDK
await Eppo.initialize('your-sdk-key', subjectEvaluation, clientConfiguration);

Use the SDK instance

After initialization, you can use the SDK singleton to assign a variation to a subject using the assignment methods.

final bool variation = Eppo.getBooleanAssignment(
'<flag-key>',
false,
);

Example Configuration

Here's an example of initializing the SDK with custom configuration:

import 'package:eppo/eppo.dart';

class YourAssignmentLogger implements AssignmentLogger {
@override
void logAssignment(AssignmentEvent event) {
print('warehouse assignment logged:', event.toJson());
}
}

class YourBanditLogger implements BanditLogger {
@override
void logBanditEvent(BanditEvent event) {
print('warehouse bandit logged:', event.toJson());
}
}

// Initialize the SDK
await Eppo.initialize(
'your-sdk-key',
SubjectEvaluation(
subject: Subject(
subjectKey: 'user-identifier',
subjectAttributes: {
'age': 30,
'country': 'usa',
}
),
banditActions: {
'test-bandit': {
'action1': {'price': 10.99, 'category': 'electronics'},
'action2': {'price': 5.99, 'category': 'books'}
}
}
),
ClientConfiguration(
assignmentLogger: YourAssignmentLogger(),
banditLogger: YourBanditLogger(),
),
);

Configuration Caching

The SDK caches configurations in memory to ensure fast assignment evaluations. The cache is automatically updated when new configurations are fetched from the Eppo Edge server.

Best Practices

  1. Initialize Once: The SDK is a singleton, initialize it once at application startup and reuse it throughout your application.
  2. Wait for Readiness: Optionally, await initialize before making assignments to ensure configurations are loaded.
  3. Implement Proper Logging: Configure an assignment logger to ensure experiment data is captured correctly.
  4. Use Subjects Consistently: Ensure that subject IDs are consistent across your application to maintain experiment integrity.