flushPendingProperties method
void
flushPendingProperties()
Implementation
void flushPendingProperties() {
Element? target = this.target;
// If style target element not exists, no need to do flush operation.
if (target == null) return;
// Display change from none to other value that the renderBoxModel is null.
if (_pendingProperties.containsKey(DISPLAY) && target.isConnected) {
CSSPropertyValue? prevValue = _properties[DISPLAY];
CSSPropertyValue currentValue = _pendingProperties[DISPLAY]!;
_properties[DISPLAY] = currentValue;
_pendingProperties.remove(DISPLAY);
_emitPropertyChanged(DISPLAY, prevValue?.value, currentValue.value,
baseHref: currentValue.baseHref);
}
if (_pendingProperties.isEmpty) {
return;
}
Map<String, CSSPropertyValue> pendingProperties = _pendingProperties;
// Reset first avoid set property in flush stage.
_pendingProperties = {};
if (pendingProperties.length == 1) {
final MapEntry<String, CSSPropertyValue> entry =
pendingProperties.entries.first;
final String propertyName = entry.key;
final CSSPropertyValue currentValue = entry.value;
final CSSPropertyValue? prevValue = _properties[propertyName];
_properties[propertyName] = currentValue;
_emitPropertyChanged(propertyName, prevValue?.value, currentValue.value,
baseHref: currentValue.baseHref);
onStyleFlushed?.call(<String>[propertyName]);
return;
}
final List<String> variablePropertyNames = <String>[];
final List<CSSPropertyValue?> variablePrevValues =
<CSSPropertyValue?>[];
final List<String?> prioritizedPropertyNames =
List<String?>.filled(_propertyFlushPriorityOrder.length, null);
final List<CSSPropertyValue?> prioritizedPrevValues =
List<CSSPropertyValue?>.filled(_propertyFlushPriorityOrder.length, null);
final List<String> regularPropertyNames = <String>[];
final List<CSSPropertyValue?> regularPrevValues = <CSSPropertyValue?>[];
for (final MapEntry<String, CSSPropertyValue> entry
in pendingProperties.entries) {
final String propertyName = entry.key;
final CSSPropertyValue currentValue = entry.value;
final CSSPropertyValue? prevValue = _properties[propertyName];
_properties[propertyName] = currentValue;
if (CSSVariable.isCSSSVariableProperty(propertyName)) {
variablePropertyNames.add(propertyName);
variablePrevValues.add(prevValue);
continue;
}
final int? priorityRank = _propertyFlushPriorityRanks[propertyName];
if (priorityRank != null) {
prioritizedPropertyNames[priorityRank] = propertyName;
prioritizedPrevValues[priorityRank] = prevValue;
continue;
}
regularPropertyNames.add(propertyName);
regularPrevValues.add(prevValue);
}
final StyleFlushedListener? styleFlushed = onStyleFlushed;
final List<String>? flushedPropertyNames =
styleFlushed == null ? null : <String>[];
_flushOrderedPendingProperties(variablePropertyNames, variablePrevValues,
pendingProperties, flushedPropertyNames);
_flushPrioritizedPendingProperties(prioritizedPropertyNames,
prioritizedPrevValues, pendingProperties, flushedPropertyNames);
_flushOrderedPendingProperties(regularPropertyNames, regularPrevValues,
pendingProperties, flushedPropertyNames);
if (flushedPropertyNames != null) {
styleFlushed!(flushedPropertyNames);
}
}