getDryLayout method Null safety
- 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) {
Map<String, String>? debugTimelineArguments;
assert(() {
if (debugEnhanceLayoutTimelineArguments) {
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
} else {
debugTimelineArguments = <String, String>{};
}
debugTimelineArguments!['getDryLayout constraints'] = '$constraints';
return true;
}());
if (!kReleaseMode) {
if (debugProfileLayoutsEnabled || _debugIntrinsicsDepth == 0) {
Timeline.startSync(
'$runtimeType.getDryLayout',
arguments: debugTimelineArguments,
);
}
_debugIntrinsicsDepth += 1;
}
_cachedDryLayoutSizes ??= <BoxConstraints, Size>{};
final Size result = _cachedDryLayoutSizes!.putIfAbsent(constraints, () => _computeDryLayout(constraints));
if (!kReleaseMode) {
_debugIntrinsicsDepth -= 1;
if (debugProfileLayoutsEnabled || _debugIntrinsicsDepth == 0) {
Timeline.finishSync();
}
}
return result;
}
return _computeDryLayout(constraints);
}