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-typescache-lru. One tracked cache key's last-access metadata. - CacheLruIndex
-
Sidecar LRU index persisted by cache providers via
readCacheLruIndex/writeCacheLruIndex. - EntityGate
- EntityGateRule
- 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
enabledboolean to builder. - HttpService
-
Simple
Diowrapper 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.
- TogglyEntityContext
- TogglyFeatureFlagsCache
- 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
-
applyEntityGate(
EntityGate gate, Map< String, dynamic> attributes) → bool -
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.
-
clearRegisteredContexts(
) → void -
emptyCacheLruIndex(
) → CacheLruIndex - Empty index with no tracked keys.
-
evaluateEvaluatedGate(
Map< String, dynamic> features, List<String> featureKeys, {bool requirementAll = true, bool negate = false, TogglyEntityContext? entityContext}) → bool -
evaluateResolvedKeys(
List< String> featureKeys, bool requirementAll, bool negate, bool isEnabled(String key)) → bool -
evaluateStoredFeatureKeys(
Map< String, dynamic> ? features, List<String> featureKeys, bool requirementAll, bool negate, bool isEnabled(String key)) → bool -
isCacheLruEnabled(
int? maxCacheKeys) → bool - True when a positive finite max is configured.
-
isEntityGate(
dynamic value) → bool -
isLocalPrerequisiteMet(
String flagKey, List< LocalGate> gates, FlagGateIndex gateIndex) → bool - Returns whether the local prerequisite allows the flag (true when ungated).
-
mapEntityContext(
String kind, dynamic entity, [EntityContextMapper? mapper]) → TogglyEntityContext? -
normalizeEntityContext(
dynamic context, [String? kind]) → TogglyEntityContext? -
parseCacheLruIndex(
String? raw) → CacheLruIndex - Parses sidecar JSON; corrupt or missing payloads become an empty index.
-
parseDefinitionValue(
dynamic value) → dynamic -
parseEvaluatedDefinitions(
dynamic raw) → Map< String, dynamic> -
registerContext(
String kind, EntityContextMapper mapper) → void -
removeCacheLruKeys(
CacheLruIndex index, List< String> keys) → CacheLruIndex -
Drops
keysfrom the index. -
resolveEntityContext(
String kind, dynamic entity) → TogglyEntityContext? -
resolveEvaluatedDefinition(
dynamic value, {TogglyEntityContext? context, bool defaultValue = false}) → bool -
selectCacheLruKeysToEvict(
CacheLruIndex index, int maxKeys, {String? protectKey, Iterable< String> ? protectKeys}) → List<String> -
Oldest keys to remove so
indexlength is at mostmaxKeys. -
serializeCacheLruIndex(
CacheLruIndex index) → String -
Serializes
indexto the JS-compatible JSON shape. -
shouldFetchOnSync(
{required bool unchanged, String? messageEtag, String? cachedRevision, bool hasSuccessfulSync = true}) → bool -
toBooleanDefinitions(
Map< String, dynamic> definitions, {TogglyEntityContext? context}) → Map<String, bool> -
touchCacheLruKey(
CacheLruIndex index, String key, {int? now}) → CacheLruIndex -
Upserts
keywithnow(epoch ms) as lastAccessed. -
tryParseEntityGate(
Map< String, dynamic> obj) → EntityGate?
Typedefs
- EntityContextMapper = TogglyEntityContext Function(dynamic entity)
-
FlagGateIndex
= Map<
String, String>
Exceptions / Errors
- TogglyMissingAppKeyException
- Handled missing app key exception used for fallback on cache/flag defaults.