layout method
void
layout(
- ParentRect relativeRect,
- LayoutOffset offset,
- LayoutSize size,
- OverflowBounds overflowBounds, {
- LayoutOffset? revealOffset,
override
Performs the actual layout of this child within the given constraints.
This method calculates and sets the child's size and position based on
the provided constraints and the child's layout data. After calling this,
the child's size and offset properties will be valid.
Implementation
@override
void layout(
ParentRect relativeRect,
LayoutOffset offset,
LayoutSize size,
OverflowBounds overflowBounds, {
LayoutOffset? revealOffset,
}) {
double maxScrollX = parent.contentSize.width - parent.viewportSize.width;
double maxScrollY = parent.contentSize.height - parent.viewportSize.height;
maxScrollX = max(0.0, maxScrollX);
maxScrollY = max(0.0, maxScrollY);
final parentData = renderBox.parentData as LayoutBoxParentData;
parentData.offset = offsetFromLayoutOffset(offset);
parentData.revealOffset = revealOffset == null
? null
: offsetFromLayoutOffset(revealOffset);
renderBox.layout(
parentData.needLayoutBox
? BoxConstraintsWithData<LayoutBox>.tightFor(
data: LayoutBoxImpl(
size: sizeFromLayoutSize(size),
offset: offsetFromLayoutOffset(offset),
scrollX: parent.scrollOffsetX,
scrollY: parent.scrollOffsetY,
maxScrollX: maxScrollX,
maxScrollY: maxScrollY,
contentSize: sizeFromLayoutSize(parent.contentSize),
viewportSize: sizeFromLayoutSize(parent.viewportSize),
horizontalUserScrollDirection: parent.horizontalAxisDirection,
verticalUserScrollDirection: parent.verticalAxisDirection,
overflowBounds: overflowBounds,
relativeRect: relativeRect,
),
width: size.width,
height: size.height,
)
: parentData.layoutData.position == PositionType.none
? BoxConstraintsWithData<RelativePositioning>.tightFor(
data: RelativePositioning(
relativeRect: relativeRect,
),
width: size.width,
height: size.height,
)
: BoxConstraints.tight(
sizeFromLayoutSize(size),
),
parentUsesSize: true,
);
}