flushPendingProperties method
void
flushPendingProperties()
Implementation
void flushPendingProperties() {
Element? _target = 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 &&
_target.parentElement?.renderStyle.display != CSSDisplay.sliver) {
CSSPropertyValue? prevValue = _properties[DISPLAY];
CSSPropertyValue currentValue = _pendingProperties[DISPLAY]!;
_properties[DISPLAY] = currentValue;
_pendingProperties.remove(DISPLAY);
_emitPropertyChanged(DISPLAY, prevValue?.value, currentValue.value, baseHref: currentValue.baseHref);
}
RenderBoxModel? renderBoxModel = _target.renderBoxModel;
if (_pendingProperties.isEmpty || renderBoxModel == null) {
return;
}
Map<String, CSSPropertyValue> pendingProperties = _pendingProperties;
// Reset first avoid set property in flush stage.
_pendingProperties = {};
List<String> propertyNames = pendingProperties.keys.toList();
for (String propertyName in _propertyOrders) {
int index = propertyNames.indexOf(propertyName);
if (index > -1) {
propertyNames.removeAt(index);
propertyNames.insert(0, propertyName);
}
}
Map<String, CSSPropertyValue?> prevValues = {};
for (String propertyName in propertyNames) {
// Update the prevValue to currentValue.
prevValues[propertyName] = _properties[propertyName];
_properties[propertyName] = pendingProperties[propertyName]!;
}
propertyNames.sort((left, right) {
final isVariableLeft = CSSVariable.isVariable(left) ? 1 : 0;
final isVariableRight = CSSVariable.isVariable(right) ? 1 : 0;
if (isVariableLeft == 1 || isVariableRight == 1) {
return isVariableRight - isVariableLeft;
}
return 0;
});
for (String propertyName in propertyNames) {
CSSPropertyValue? prevValue = prevValues[propertyName];
CSSPropertyValue currentValue = pendingProperties[propertyName]!;
_emitPropertyChanged(propertyName, prevValue?.value, currentValue.value, baseHref: currentValue.baseHref);
}
onStyleFlushed?.call(propertyNames);
}