LDClient class interface

The main interface for the LaunchDarkly Flutter SDK.

To setup the SDK before use, construct an LDConfig and an initial LDContext with LDContextBuilder. These should be passed to LDClient(config, context) and then start should be called. A basic example:

final config = LDConfig(CredentialSource.fromEnvironment(),
  AutoEnvAttributes.enabled);
final context = LDContextBuilder()
  .kind("user", <USER_KEY>)
  .kind("company", <COMP_KEY>)
  .build();
final client = LDClient(config, context);
await client.start().timeout(const Duration(seconds: 5), onTimeout: () => false);

After initialization, the SDK can evaluate feature flags from the LaunchDarkly dashboard against the current context, record custom events, and provides various status configuration and monitoring utilities.

See the individual class and method documentation for more details.

This is an interface class so that it can be mocked for testing, but it cannot be extended.

Constructors

LDClient(LDConfig config, LDContext context)
Construct the client instance.

Properties

dataSourceStatus DataSourceStatus
Get the current data source status.
no setter
dataSourceStatusChanges Stream<DataSourceStatus>
Stream which emits data source status changes.
no setter
flagChanges Stream<FlagsChangedEvent>
Stream which emits flag changes.
no setter
hashCode int
The hash code for this object.
no setterinherited
initialized bool
Check if the SDK has finished initialization.
no setter
offline bool
Returns whether the SDK is currently configured not to make network connections.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

allFlags() Map<String, LDValue>
Returns a map of all feature flags for the current context, without sending evaluation events to LaunchDarkly.
boolVariation(String flagKey, bool defaultValue) bool
Returns the value of flag flagKey for the current context as a bool.
boolVariationDetail(String flagKey, bool defaultValue) LDEvaluationDetail<bool>
Returns the value of flag flagKey for the current context as a bool, along with information about the resultant value.
close() Future<void>
Permanently shuts down the client.
doubleVariation(String flagKey, double defaultValue) double
Returns the value of flag flagKey for the current context as a double.
doubleVariationDetail(String flagKey, double defaultValue) LDEvaluationDetail<double>
Returns the value of flag flagKey for the current context as a double, along with information about the resultant value.
flush() Future<void>
Triggers immediate sending of pending events to LaunchDarkly.
identify(LDContext context) Future<IdentifyResult>
Changes the active context.
intVariation(String flagKey, int defaultValue) int
Returns the value of flag flagKey for the current context as an int.
intVariationDetail(String flagKey, int defaultValue) LDEvaluationDetail<int>
Returns the value of flag flagKey for the current context as an int, along with information about the resultant value.
jsonVariation(String flagKey, LDValue defaultValue) LDValue
Returns the value of flag flagKey for the current context as an LDValue.
jsonVariationDetail(String flagKey, LDValue defaultValue) LDEvaluationDetail<LDValue>
Returns the value of flag flagKey for the current context as an LDValue, along with information about the resultant value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() Future<bool>
Initialize the SDK.
stringVariation(String flagKey, String defaultValue) String
Returns the value of flag flagKey for the current context as a string.
stringVariationDetail(String flagKey, String defaultValue) LDEvaluationDetail<String>
Returns the value of flag flagKey for the current context as a string, along with information about the resultant value.
toString() String
A string representation of this object.
inherited
track(String eventName, {LDValue? data, num? metricValue}) → void
Track custom events associated with the current context for data export or experimentation.

Operators

operator ==(Object other) bool
The equality operator.
inherited