computeDryLayout method

  1. @override
Size computeDryLayout(
  1. covariant BoxConstraints constraints
)
override

Computes the value returned by getDryLayout. Do not call this function directly, instead, call getDryLayout.

Override in subclasses that implement performLayout or performResize or when setting sizedByParent to true without overriding performResize. This method should return the Size that this RenderBox would like to be given the provided BoxConstraints.

The size returned by this method must match the size that the RenderBox will compute for itself in performLayout (or performResize, if sizedByParent is true).

If this algorithm depends on the size of a child, the size of that child should be obtained using its getDryLayout method.

This layout is called "dry" layout as opposed to the regular "wet" layout run performed by performLayout because it computes the desired size for the given constraints without changing any internal state.

When the size cannot be known

There are cases where render objects do not have an efficient way to compute their size. For example, the size may computed by a callback about which the render object cannot reason.

In such cases, it may be impossible (or at least impractical) to actually return a valid answer. In such cases, the function should call debugCannotComputeDryLayout from within an assert and return a dummy value of const Size(0, 0).

Implementation

@override
Size computeDryLayout(BoxConstraints constraints) {
  if (!_canComputeIntrinsics) {
    assert(debugCannotComputeDryLayout(
        reason: 'Dry layout cannot be computed for CrossAxisAlignment.baseline, which requires a full layout.'
    ));
    return Size.zero;
  }
  FlutterError? constraintsError;
  assert(() {
    constraintsError = _debugCheckConstraints(
      constraints: constraints,
      reportParentConstraints: false,
    );
    return true;
  }());
  if (constraintsError != null) {
    assert(debugCannotComputeDryLayout(error: constraintsError));
    return Size.zero;
  }

  final _LayoutSizes sizes = _computeSizes(
    layoutChild: (RenderBox child, BoxConstraints constraints) {
      final size = child.getDryLayout(constraints);
      final childParentData = child.parentData as BoxyFlexParentData;
      childParentData._tempSize = child.size;
      return size;
    },
    constraints: constraints,
  );

  switch (_direction) {
    case Axis.horizontal:
      return constraints.constrain(Size(sizes.mainSize, sizes.crossSize));
    case Axis.vertical:
      return constraints.constrain(Size(sizes.crossSize, sizes.mainSize));
  }
}