recalculateStyle method
void
recalculateStyle(
{ - bool rebuildNested = false,
- bool forceRecalculate = false,
})
Implementation
void recalculateStyle(
{bool rebuildNested = false, bool forceRecalculate = false}) {
// Pseudo elements (::before/::after) are styled via their parent's
// matched pseudo rules. A full recalc using the standard element
// pipeline would discard those properties (only defaults/inline apply).
// Skip full recalc here to preserve pseudo-specific styles, which are
// refreshed via markBefore/AfterPseudoElementNeedsUpdate on the parent.
if (this is PseudoElement) {
// Still flush any pending inline or merged properties if present.
style.flushPendingProperties();
return;
}
// Always update CSS variables even for display:none elements when rebuilding nested
bool shouldUpdateCSSVariables =
rebuildNested && renderStyle.display == CSSDisplay.none;
if (forceRecalculate ||
renderStyle.display != CSSDisplay.none ||
shouldUpdateCSSVariables) {
// Diff style.
CSSStyleDeclaration newStyle = CSSStyleDeclaration();
applyStyle(newStyle);
var hasInheritedPendingProperty = false;
if (style.merge(newStyle)) {
hasInheritedPendingProperty = style.hasInheritedPendingProperty;
style.flushPendingProperties();
}
if (rebuildNested || hasInheritedPendingProperty) {
// Update children style.
for (final Element child in children) {
child.recalculateStyle(
rebuildNested: rebuildNested, forceRecalculate: forceRecalculate);
}
}
}
}