computeSize method
double
computeSize({
- required ParentLayout parent,
- required ChildLayout child,
- required LayoutHandle<
Layout> layoutHandle, - required LayoutAxis axis,
- required LayoutSize contentSize,
- required LayoutSize viewportSize,
override
Returns the size that fits the child's content exactly.
This performs a dry layout of the child with no constraints to determine its natural size, then returns the width or height along the specified axis. The result is cached to avoid repeated layout calculations.
Implementation
@override
double computeSize({
required ParentLayout parent,
required ChildLayout child,
required LayoutHandle layoutHandle,
required LayoutAxis axis,
required LayoutSize contentSize,
required LayoutSize viewportSize,
}) {
LayoutSize? cachedSize = child.layoutCache.cachedFitContentSize;
if (cachedSize == null) {
cachedSize = child.dryLayout(LayoutConstraints());
child.layoutCache.cachedFitContentSize = cachedSize;
}
return switch (axis) {
LayoutAxis.horizontal => cachedSize.width,
LayoutAxis.vertical => cachedSize.height,
};
}