updateRenderObject method
Updates the render object when widget properties change.
This method efficiently updates only the properties that have changed, minimizing unnecessary layout or paint operations. It tracks whether a full layout or just a repaint is needed based on which properties changed.
Implementation
@override
void updateRenderObject(
BuildContext context,
covariant RenderLayoutBox renderObject,
) {
bool needsPaint = false;
bool needsLayout = false;
if (renderObject.layoutTextDirection != textDirection) {
renderObject.layoutTextDirection = textDirection;
needsLayout = true;
}
if (renderObject.reversePaint != reversePaint) {
renderObject.reversePaint = reversePaint;
needsPaint = true;
}
if (renderObject.mainScrollDirection != mainScrollDirection) {
renderObject.mainScrollDirection = mainScrollDirection;
needsLayout = true;
}
if (renderObject.horizontal != horizontal) {
renderObject.updateHorizontalOffset(horizontal);
needsLayout = true;
}
if (renderObject.vertical != vertical) {
renderObject.updateVerticalOffset(vertical);
needsLayout = true;
}
if (renderObject.horizontalAxisDirection != horizontalAxisDirection) {
renderObject.horizontalAxisDirection = horizontalAxisDirection;
needsLayout = true;
}
if (renderObject.verticalAxisDirection != verticalAxisDirection) {
renderObject.verticalAxisDirection = verticalAxisDirection;
needsLayout = true;
}
if (renderObject.boxLayout != layout) {
renderObject.boxLayout = layout;
needsLayout = true;
}
if (renderObject.horizontalOverflow != horizontalOverflow) {
renderObject.horizontalOverflow = horizontalOverflow;
needsPaint = true;
}
if (renderObject.verticalOverflow != verticalOverflow) {
renderObject.verticalOverflow = verticalOverflow;
needsPaint = true;
}
if (renderObject.layoutTextBaseline != textBaseline) {
renderObject.layoutTextBaseline = textBaseline;
needsLayout = true;
}
if (renderObject.borderRadius != borderRadius) {
renderObject.borderRadius = borderRadius;
needsPaint = true;
}
if (renderObject.clipBehavior != clipBehavior) {
renderObject.clipBehavior = clipBehavior;
needsPaint = true;
}
if (needsLayout) {
renderObject.markNeedsLayout();
} else if (needsPaint) {
renderObject.markNeedsPaint();
}
}