performLayout method
Do the work of computing the layout for this render object.
Do not call this function directly: call layout instead. This function is called by layout when there is actually work to be done by this render object during layout. The layout constraints provided by your parent are available via the constraints getter.
If sizedByParent is true, then this function should not actually change the dimensions of this render object. Instead, that work should be done by performResize. If sizedByParent is false, then this function should both change the dimensions of this render object and instruct its children to layout.
In implementing this function, you must call layout on each of your children, passing true for parentUsesSize if your layout information is dependent on your child's layout information. Passing true for parentUsesSize ensures that this render object will undergo layout if the child undergoes layout. Otherwise, the child can change its layout information without informing this render object.
Implementation
@override
void performLayout() {
final SliverGeometry geometry;
if (sliver != null) {
sliver!.layout(constraints, parentUsesSize: true);
geometry = sliver!.geometry!;
} else {
geometry = SliverGeometry.zero;
}
this.geometry = geometry;
final maxBufferExtent = min(
bufferExtent,
geometry.maxPaintExtent / 2,
);
var start = -min(constraints.scrollOffset, maxBufferExtent);
var end = min(geometry.maxPaintExtent - constraints.scrollOffset,
geometry.paintExtent + maxBufferExtent);
if (constraints.scrollOffset > 0) {
start = min(start, end - maxBufferExtent * 2);
} else {
end = max(end, start + maxBufferExtent * 2);
}
switch (constraints.axisDirection) {
case AxisDirection.up:
case AxisDirection.left:
_rightWayUp = false;
break;
case AxisDirection.down:
case AxisDirection.right:
_rightWayUp = true;
break;
}
switch (constraints.growthDirection) {
case GrowthDirection.reverse:
_rightWayUp = !_rightWayUp;
break;
default:
break;
}
_bufferMainSize = end - start;
final boxConstraints = BoxConstraintsAxisUtil.tightFor(
constraints.axis,
cross: constraints.crossAxisExtent,
main: _bufferMainSize,
);
final newRect =
_getBufferOffset(start, _bufferMainSize) & boxConstraints.biggest;
if (_bufferRect == null || newRect.size != _bufferRect!.size) {
_markNeedsClip();
}
_bufferRect = newRect;
if (foreground != null) {
foreground!.layout(boxConstraints);
}
if (background != null) {
background!.layout(boxConstraints);
}
}