setCSSVariable method
void
setCSSVariable(
- String identifier,
- String value
)
override
Implementation
@override
void setCSSVariable(String identifier, String value) {
final List<String>? deps = _propertyDependencies[identifier];
if (DebugFlags.shouldLogCssVar(identifier, deps)) {
cssLogger.info('[var][set] id=$identifier new="$value" target=${target.tagName}');
}
// Snapshot old value before mutation for transition heuristics.
// Prefer the exact prior token text, including alias var(...) if present.
String? prevRaw = _identifierStorage != null ? _identifierStorage![identifier] : null;
if (prevRaw == null && _variableStorage != null && _variableStorage![identifier] != null) {
// Preserve the alias token form, e.g., 'var(--a[, fallback])'.
prevRaw = _variableStorage![identifier]!.toString();
}
if (isSingleVarFunction(value)) {
CSSVariable? variable = CSSVariable.tryParse(this, value);
if (variable != null) {
_variableStorage ??= HashMap<String, CSSVariable>();
_variableStorage![identifier] = variable;
if (DebugFlags.shouldLogCssVar(identifier, deps)) {
cssLogger.info('[var][set] id=$identifier stored-as=alias prev=${prevRaw ?? 'null'}');
}
} else {
_identifierStorage ??= HashMap<String, String>();
_identifierStorage![identifier] = value;
if (DebugFlags.shouldLogCssVar(identifier, deps)) {
cssLogger.info('[var][set] id=$identifier stored-as=raw prev=${prevRaw ?? 'null'}');
}
}
} else {
_identifierStorage ??= HashMap<String, String>();
_identifierStorage![identifier] = value;
if (DebugFlags.shouldLogCssVar(identifier, deps)) {
cssLogger.info('[var][set] id=$identifier stored-as=raw prev=${prevRaw ?? 'null'}');
}
}
if (_propertyDependencies.containsKey(identifier)) {
if (DebugFlags.shouldLogCssVar(identifier, _propertyDependencies[identifier])) {
cssLogger.info('[var][notify] id=$identifier deps=${_propertyDependencies[identifier]?.join(',') ?? '[]'}');
}
_notifyCSSVariableChanged(identifier, value, prevRaw);
} else {
// No dependencies recorded yet (e.g., first parse may have used a cached color string).
// Clear common color cache keys so next parse recomputes with the new variable value.
_clearColorCacheForVariable(identifier);
if (DebugFlags.shouldLogCssVar(identifier)) {
cssLogger.info('[var][notify] id=$identifier no-deps; cleared-color-cache-only');
}
}
}