flagnetic library

Flagnetic feature flags and experiments for Dart apps: a client that posts a context to remote evaluation with a client key and serves every flag's value from memory through the fallback chain: fresh values, else the last good values from the store, else built-in defaults.

final client = Flagnetic.client(
  'fn_cli_…',
  baseUrl: Uri.parse('https://flags.example.com'),
  context: const FlagneticContext(units: {'anonymous': 'd-8f1c'}),
  options: const ClientOptions(platform: 'android', appVersion: '1.42.0'),
);
final checkout = client.getBool('checkout', false); // synchronous
await client.ready(const Duration(seconds: 2));

There is no evaluator in this package: a client key never receives a ruleset, only the values the platform evaluated for its context.

Classes

ClientOptions
How a client behaves. Every duration is configurable so that a test can run a whole scenario in milliseconds.
Detail
A served value and why it was served.
Experiment
The experiment block of a served value: everything an exposure reports, so an analyst can recompute both buckets.
FallbackCodes
Why a Detail has reason fallback, by wire name. The error codes of the server's evaluator (inconsistent_ruleset, prerequisite_cycle, …) are passed through as they arrived.
Flagnetic
The entry point of the Flagnetic SDK: client builds a client-mode client.
FlagneticClient
A client-mode client: values from remote evaluation, cached on device as last good, served through the fallback chain. Every public member is total: an internal failure is logged and never escapes.
FlagneticContext
Who a flag is evaluated for: units identify the subjects experiments bucket by, attributes feed targeting.
FlagneticStore
Where a client keeps what must survive a restart: the last good values of each recent unit set, its event queue and its local overrides. Keys and values are strings; an implementation may answer synchronously or with a future. Shared preferences, secure storage or an app database all fit.
FlagSummary
One flag's current state, for a Dev Tools screen listing every flag: not an evaluation of it, so reading FlagneticClient.allFlags records nothing in the evaluation summary. Empty at stage built_in.
InMemoryStore
A FlagneticStore in memory: nothing survives the process. The default store, and the one tests use.
LocalOverrides
Local overrides: substitutions of flag values inside this process that never reach the platform. An overridden flag reads reason local_override, with no experiment block and the stage unchanged, so exposure is a no-op for it. They exist only with the allowOverrides option and are refused in a protected environment. Obtain this through the client's overrides.
LogEvents
Stable log event names: alert on them.
OfflineMode
The test helpers of an offline client: no network at all, stage fresh, events recorded in memory.
OfflineSource
A document to serve instead of the network: a values document, exactly what remote evaluation returns. A document saved from the platform works as is.
Reasons
Evaluation reasons by wire name. A client key learns only that targeting decided a value, never which rule, rollout or prerequisite did, so the server answers it targetingMatch where it would answer a server key with a finer reason. The SDK produces localOverride and fallback. A reason the SDK does not know is passed through as it arrived.
Status
The stage of a client and how long its values have been stale.
StoreKeys
The keys one SDK key writes. An app that talks to two environments, or to two installations, shares one store between them, and neither may serve the other's values or send the other's events under its own key. The SDK key, which is what names an environment of an installation, names every key; the unit set names only the values. The base URL takes no part: the same key behind a proxy, a renamed host or another port is the same environment.

Enums

LogLevel
The severity of a log event.
Stage
The step of the fallback chain a client serves from.

Functions

anonymousUnitId(FlagneticStore store, String unitType, {Logger? logger}) → Future<String>
The unit ID this device (this origin in a browser) uses for the anonymous unit type unitType, generating and persisting a random one the first time.
anonymousUnitIdKey(String unitType) → String
The store key holding the anonymous unit ID of unitType.
isLastGoodValuesKey(String key) → bool
True when key holds one unit set's last good values: a whole evaluate response, which a store may want to keep somewhere other than its small entries. The index of unit sets and an anonymous unit ID are not.

Typedefs

ChangeListener = void Function(List<String> changedKeys)
A listener of changed flag keys.
Logger = void Function(LogLevel level, String event, Map<String, Object?> fields)
Receives every log event: its level, a stable name from LogEvents and structured fields. Called synchronously; an exception it throws is swallowed.
StageListener = void Function(Stage stage)
A listener of stage transitions.
SummaryRow = ({int count, String flag, String reason, String? variation})
One row of an evaluation summary: one flag, one variation, one evaluation reason and how often it was served. No unit ID, attribute or flag value is in it, by construction.