# 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 SliverConstraints constraints = this.constraints;
double paintOffset({required double from, required double to}) => calculatePaintOffset(constraints, from: from, to: to);
double cacheOffset({required double from, required double to}) => calculateCacheOffset(constraints, from: from, to: to);
assert(this.resolvedPadding != null);
final EdgeInsets resolvedPadding = this.resolvedPadding!;
final double beforePadding = this.beforePadding;
final double afterPadding = this.afterPadding;
final double mainAxisPadding = this.mainAxisPadding;
final double crossAxisPadding = this.crossAxisPadding;
if (child == null) {
final double paintExtent = paintOffset(from: 0.0, to: mainAxisPadding);
final double cacheExtent = cacheOffset(from: 0.0, to: mainAxisPadding);
geometry = SliverGeometry(
scrollExtent: mainAxisPadding,
paintExtent: math.min(paintExtent, constraints.remainingPaintExtent),
maxPaintExtent: mainAxisPadding,
cacheExtent: cacheExtent,
);
return;
}
final double beforePaddingPaintExtent = paintOffset(from: 0.0, to: beforePadding);
double overlap = constraints.overlap;
if (overlap > 0) {
overlap = math.max(0.0, constraints.overlap - beforePaddingPaintExtent);
}
child!.layout(
constraints.copyWith(
scrollOffset: math.max(0.0, constraints.scrollOffset - beforePadding),
cacheOrigin: math.min(0.0, constraints.cacheOrigin + beforePadding),
overlap: overlap,
remainingPaintExtent: constraints.remainingPaintExtent - paintOffset(from: 0.0, to: beforePadding),
remainingCacheExtent: constraints.remainingCacheExtent - cacheOffset(from: 0.0, to: beforePadding),
crossAxisExtent: math.max(0.0, constraints.crossAxisExtent - crossAxisPadding),
precedingScrollExtent: beforePadding + constraints.precedingScrollExtent,
),
parentUsesSize: true,
);
final SliverGeometry childLayoutGeometry = child!.geometry!;
if (childLayoutGeometry.scrollOffsetCorrection != null) {
geometry = SliverGeometry(
scrollOffsetCorrection: childLayoutGeometry.scrollOffsetCorrection,
);
return;
}
final double scrollExtent = childLayoutGeometry.scrollExtent;
final double beforePaddingCacheExtent = cacheOffset(from: 0.0, to: beforePadding);
final double afterPaddingCacheExtent = cacheOffset(from: beforePadding + scrollExtent, to: mainAxisPadding + scrollExtent);
final double afterPaddingPaintExtent = paintOffset(from: beforePadding + scrollExtent, to: mainAxisPadding + scrollExtent);
final double mainAxisPaddingCacheExtent = beforePaddingCacheExtent + afterPaddingCacheExtent;
final double mainAxisPaddingPaintExtent = beforePaddingPaintExtent + afterPaddingPaintExtent;
final double paintExtent = math.min(
beforePaddingPaintExtent + math.max(childLayoutGeometry.paintExtent, childLayoutGeometry.layoutExtent + afterPaddingPaintExtent),
constraints.remainingPaintExtent,
);
geometry = SliverGeometry(
paintOrigin: childLayoutGeometry.paintOrigin,
scrollExtent: mainAxisPadding + scrollExtent,
paintExtent: paintExtent,
layoutExtent: math.min(mainAxisPaddingPaintExtent + childLayoutGeometry.layoutExtent, paintExtent),
cacheExtent: math.min(mainAxisPaddingCacheExtent + childLayoutGeometry.cacheExtent, constraints.remainingCacheExtent),
maxPaintExtent: mainAxisPadding + childLayoutGeometry.maxPaintExtent,
hitTestExtent: math.max(
mainAxisPaddingPaintExtent + childLayoutGeometry.paintExtent,
beforePaddingPaintExtent + childLayoutGeometry.hitTestExtent,
),
hasVisualOverflow: childLayoutGeometry.hasVisualOverflow,
);
final double calculatedOffset = switch (applyGrowthDirectionToAxisDirection(constraints.axisDirection, constraints.growthDirection)) {
AxisDirection.up => paintOffset(from: resolvedPadding.bottom + scrollExtent, to: resolvedPadding.vertical + scrollExtent),
AxisDirection.left => paintOffset(from: resolvedPadding.right + scrollExtent, to: resolvedPadding.horizontal + scrollExtent),
AxisDirection.right => paintOffset(from: 0.0, to: resolvedPadding.left),
AxisDirection.down => paintOffset(from: 0.0, to: resolvedPadding.top),
};
final SliverPhysicalParentData childParentData = child!.parentData! as SliverPhysicalParentData;
childParentData.paintOffset = switch (constraints.axis) {
Axis.horizontal => Offset(calculatedOffset, resolvedPadding.top),
Axis.vertical => Offset(resolvedPadding.left, calculatedOffset),
};
assert(beforePadding == this.beforePadding);
assert(afterPadding == this.afterPadding);
assert(mainAxisPadding == this.mainAxisPadding);
assert(crossAxisPadding == this.crossAxisPadding);
}
```