Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations.
This is the SDK for Flutter for https://www.flagsmith.com/.
For full documentation visit https://docs.flagsmith.com/clients/flutter/
Once an experiment is running, Flagsmith serves the variations automatically through the flag. Your application records exposures (when an identity experienced a variation) and conversion events (what your metrics aggregate).
Enable event collection with enableEvents. Users must be identified: exposures and conversion events are joined per
identity, so use the same identifier for flags and events.
final flagsmith = await FlagsmithClient.init(
apiKey: 'YOUR_CLIENT_SIDE_ENVIRONMENT_KEY',
config: const FlagsmithConfig(enableEvents: true),
);
final user = Identity(identifier: 'user_42');
await flagsmith.getFeatureFlags(user: user);
// Evaluate the flag and record an exposure in one call
final flag = await flagsmith.getExperimentFlag('checkout_button', user: user);
// ...render based on flag?.variant / flag?.stateValue
// Record a conversion event; the name must match your metric's event name
flagsmith.trackEvent('purchase', value: 99.5);getExperimentFlag evaluates the flag and records a $flag_exposure event with the served variant as its value. It
is only recorded when the flag exists, is enabled and the identity is enrolled (flag.experiment?.inExperiment == true).
Anything else is logged and skipped, so it is safe to call against environments or servers without experiments.
If you evaluate in one place and render in another, call trackExposureEvent at the point of display instead:
final experiment = flag?.experiment;
if (flag != null && experiment != null) {
flagsmith.trackExposureEvent('checkout_button',
value: flag.variant, metadata: {'experiment_id': experiment.id});
}Exposures are deduplicated per identity and variant within a flush window, so recording one more than once is safe.
trackEvent sends a named event, optionally with a value, traits and metadata. Names starting with $ are
reserved. The event name is case-sensitive and must match the metric's configured event name.
Events are buffered and posted to eventsURI every eventsFlushInterval ms (10 s) or when eventsMaxBuffer (1000)
events are queued. close() flushes best-effort; await flushEvents() when you need the POST to complete, e.g. before
the app is torn down. Network failures are retried once, then logged and dropped; they never throw.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.
If you have any questions about our projects you can email support@flagsmith.com.
