layoutChildSequence method
Primary work horse of performLayout.
Subclasses must implement this method to layout the children of the viewport. The TwoDimensionalViewportParentData.layoutOffset must be set during this method in order for the children to be positioned during paint. Further, children of the viewport must be laid out with the expectation that the parent (this viewport) will use their size.
child.layout(constraints, parentUsesSize: true);
The primary methods used for creating and obtaining children is buildOrObtainChildFor, which takes a ChildVicinity that is used by the TwoDimensionalChildDelegate. If a child is not provided by the delegate for the provided vicinity, the method will return null, otherwise, it will return the RenderBox of the child.
After layoutChildSequence is completed, any remaining children that were not obtained will be disposed.
Implementation
@override
void layoutChildSequence() {
double horizontalPixels = horizontalOffset.pixels;
double verticalPixels = verticalOffset.pixels;
final Size viewportDimension = this.viewportDimension;
final ChildVicinity vicinity = _ScrollableClientChildVicinity(
viewportSize: viewportDimension,
xIndex: 0,
yIndex: 0,
);
final RenderBox child = buildOrObtainChildFor(vicinity)!;
child.layout(
BoxConstraints(
minWidth: constraints.maxWidth,
minHeight: constraints.maxHeight,
),
parentUsesSize: true);
if (!overscroll) {
horizontalPixels = max(0.0, horizontalPixels);
verticalPixels = max(0.0, verticalPixels);
double maxHorizontalPixels = child.size.width - viewportDimension.width;
double maxVerticalPixels = child.size.height - viewportDimension.height;
horizontalPixels = min(horizontalPixels, maxHorizontalPixels);
verticalPixels = min(verticalPixels, maxVerticalPixels);
}
parentDataOf(child).layoutOffset =
Offset(-horizontalPixels, -verticalPixels);
horizontalOffset.applyContentDimensions(
0,
(child.size.width - viewportDimension.width)
.clamp(0.0, double.infinity));
verticalOffset.applyContentDimensions(
0,
(child.size.height - viewportDimension.height)
.clamp(0.0, double.infinity));
horizontalOffset.applyViewportDimension(viewportDimension.width);
verticalOffset.applyViewportDimension(viewportDimension.height);
}