EvaluationContext.immutable constructor
EvaluationContext.immutable({
- String? targetingKey,
- Map<
String, dynamic> attributes = const {}, - EvaluationContext? parent,
- List<
TargetingRule> rules = const [], - Duration cacheDuration = const Duration(minutes: 5),
Copies and freezes evaluation fields, including nested maps/lists.
Rule operands outside maps/lists are retained by reference; callers must
keep custom mutable operands stable for the lifetime of the snapshot.
The map-form targetingKey is a compatibility alias for targetingKey;
an explicit argument takes precedence at the same context level.
Implementation
factory EvaluationContext.immutable({
String? targetingKey,
Map<String, dynamic> attributes = const {},
EvaluationContext? parent,
List<TargetingRule> rules = const [],
Duration cacheDuration = const Duration(minutes: 5),
}) {
final mapKey = attributes['targetingKey'];
if (attributes.containsKey('targetingKey') && mapKey is! String) {
throw InvalidContextException('attributes.targetingKey must be a string');
}
final localKey = targetingKey ?? mapKey as String?;
final copied = snapshotContextMap({
...attributes,
if (localKey != null) 'targetingKey': localKey,
});
return EvaluationContext._snapshot(
targetingKey: localKey,
attributes: copied,
parent: parent?.snapshot(),
rules: _snapshotRules(rules, HashSet<TargetingRule>.identity(), 'rules'),
cacheDuration: cacheDuration,
);
}