getDryLayout method Null safety

  1. @mustCallSuper
Size getDryLayout (
  1. BoxConstraints constraints
)

Returns the Size that this RenderBox would like to be given the provided BoxConstraints.

The size returned by this method is guaranteed to be the same size that this RenderBox computes for itself during layout given the same constraints.

This function should only be called on one's children. Calling this function couples the child with the parent so that when the child's layout changes, the parent is notified (via markNeedsLayout).

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.

Calling this function is expensive as it can result in O(N^2) behavior.

Do not override this method. Instead, implement computeDryLayout.

Implementation

@mustCallSuper
Size getDryLayout(BoxConstraints constraints) {
  bool shouldCache = true;
  assert(() {
    // we don't want the checked-mode intrinsic tests to affect
    // who gets marked dirty, etc.
    if (RenderObject.debugCheckingIntrinsics)
      shouldCache = false;
    return true;
  }());
  if (shouldCache) {
    _cachedDryLayoutSizes ??= <BoxConstraints, Size>{};
    return _cachedDryLayoutSizes!.putIfAbsent(constraints, () => _computeDryLayout(constraints));
  }
  return _computeDryLayout(constraints);
}