feature_flags_toggly library

Provides feature flags support for Flutter applications allowing you to enable and disable features easily. Can be used with or without Toggly.io.

Classes

CacheLruEntry
Pure LRU index helpers matching @ops-ai/toggly-hooks-types cache-lru. One tracked cache key's last-access metadata.
CacheLruIndex
Sidecar LRU index persisted by cache providers via readCacheLruIndex / writeCacheLruIndex.
Feature
Creates a feature Widget that can be enabled, disabled or partially enabled, described by the provided featureKeys and following the requirement and negate parameters.
FeatureGateBuilder
Resolves a feature gate (remote flags, local gates, requirement, negate, optional variant) and exposes the effective enabled boolean to builder.
HttpService
Simple Dio wrapper to simplify http requests across the package.
LocalGate
Device-local gate that ANDs with worker-evaluated flag booleans at read time.
LruTogglyCacheProvider
Wraps a TogglyCacheProvider with opt-in last-accessed LRU eviction.
SyncService
Simple service to simplify Timer instances management across the package.
Toggly
Static class providing feature flags support.
TogglyCacheProvider
Contract for persisting Toggly cache data across app restarts.
TogglyConfig
Toggly configuration model allowing various tweaks on how the package should work to better fit each use-case.
TogglyFeatureFlagsCache
Serializable cache models used by TogglyCacheProvider implementations to persist feature flags and variant definitions across app restarts. Data representation to be stored in/retrieved from cache.
TogglyInitResponse
Toggly initialization response model.
TogglyRevisionCacheProvider
Optional extension for TogglyCacheProvider implementations that persist the definitions revision (ETag) across app restarts.
TogglyVariantsCache
Serialized variant definitions cache (signed payloads).
VariantResult
Result of evaluating a feature flag variant from Toggly.
WsSyncMessage
WebSocket sync payload from the definitions worker.

Enums

FeatureRequirement
Feature requirement types allowing "ANY" or "ALL" operations when evaluating feature gates.
TogglyLoadFeatureFlagsResponse
Possible feature flags values loading responses.

Constants

definitionsRevisionHeader → const String
Header used by Toggly definitions endpoints for revision (falls back to ETag).

Functions

applyLocalGate(bool remote, String flagKey, List<LocalGate> gates, FlagGateIndex gateIndex) bool
Applies the local post-filter to a single remote boolean.
applyLocalGatesToMap(Map<String, bool> remoteFlags, List<LocalGate> gates, [FlagGateIndex? gateIndex]) Map<String, bool>
Applies local gates to every key in a remote flag map (for bulk/debug use).
buildFlagGateIndex(List<LocalGate> gates) FlagGateIndex
Builds a flag-key → gate-id index. Throws if a flag key appears in more than one gate.
emptyCacheLruIndex() CacheLruIndex
Empty index with no tracked keys.
isCacheLruEnabled(int? maxCacheKeys) bool
True when a positive finite max is configured.
isLocalPrerequisiteMet(String flagKey, List<LocalGate> gates, FlagGateIndex gateIndex) bool
Returns whether the local prerequisite allows the flag (true when ungated).
parseCacheLruIndex(String? raw) CacheLruIndex
Parses sidecar JSON; corrupt or missing payloads become an empty index.
removeCacheLruKeys(CacheLruIndex index, List<String> keys) CacheLruIndex
Drops keys from the index.
selectCacheLruKeysToEvict(CacheLruIndex index, int maxKeys, {String? protectKey, Iterable<String>? protectKeys}) List<String>
Oldest keys to remove so index length is at most maxKeys.
serializeCacheLruIndex(CacheLruIndex index) String
Serializes index to the JS-compatible JSON shape.
shouldFetchOnSync({required bool unchanged, String? messageEtag, String? cachedRevision, bool hasSuccessfulSync = true}) bool
touchCacheLruKey(CacheLruIndex index, String key, {int? now}) CacheLruIndex
Upserts key with now (epoch ms) as lastAccessed.

Exceptions / Errors

TogglyMissingAppKeyException
Handled missing app key exception used for fallback on cache/flag defaults.