Flutter 3.41 is live! Check out theFlutter 3.41 blog post!
Dry layout support for RenderBox
The method "computeDryLayout" was added to the RenderBox protocol to correctly calculate its intrinsic size in certain situations.
These breaking change docs are accurate, as of the release under which they are published. Over time, the workarounds described here might become inaccurate. We don't, in general, keep these breaking change docs up to date as of each release.
Thebreaking change index file lists the docs created for each release.
Summary
# A new method namedcomputeDryLayout was added to theRenderBox protocol. Subclasses ofRenderBox are expected to implement it to correctly report their desired size given a set ofBoxConstraints during intrinsic calculations. Subclasses that implementcomputeDryLayout no longer need to overrideperformResize.
Context
# A new method,computeDryLayout, was added to theRenderBox protocol to correctly calculate the intrinsic sizes of aRenderParagraph withWidgetSpan children and aRenderWrap. The method receives a set ofBoxConstraints and is expected to calculate the resulting size of theRenderBox without changing any internal state. It's essentially a dry run ofperformLayout that only calculates the resulting size and doesn't place the children. ThecomputeDryLayout method is part of the intrinsics protocol (see alsoRenderBox.computeMinIntrinsicWidth and friends).
Description of change
# Subclasses ofRenderBox need to override the newcomputeDryLayout method if they are used as a descendant of aRenderObject that may query the intrinsic size of its children. Examples of widgets that do this areIntrinsicHeight andIntrinsicWidth.
The default implementation ofRenderBox.performResize also uses the size computed bycomputeDryLayout to perform the resize. OverridingperformResize is therefore no longer necessary.
Migration guide
# Subclasses that already overrideperformResize can be migrated by simply changing the function signature fromvoid performResize() toSize computeDryLayout(BoxConstraints constraints) and by returning the calculated size instead of assigning it to thesize setter. The old implementation ofperformResize can be removed.
Code before migration:
@overridevoidperformResize(){size=constraints.biggest;}Code after migration:
// This replaces the old performResize method.@overrideSizecomputeDryLayout(BoxConstraintsconstraints){returnconstraints.biggest;} If the subclass doesn't overrideperformResize, the implementation ofcomputeDryLayout has to be extracted from theperformLayout method. Basically,computeDryLayout needs to do all the workperformLayout is doing to figure out the size of theRenderBox. However, instead of assigning it to thesize setter, it returns the computed size. IfcomputeDryLayout needs to know the size of its children, it must obtain that size by callinggetDryLayout on the child instead of callinglayout.
If for some reason it is impossible to calculate the dry layout,computeDryLayout must calldebugCannotComputeDryLayout from within an assert and return a dummy size ofconst Size(0, 0). Calculating a dry layout is, for example, impossible if the size of aRenderBox depends on the baseline metrics of its children.
@overrideSizecomputeDryLayout(BoxConstraintsconstraints){assert(debugCannotComputeDryLayout(reason:'Layout requires baseline metrics, which are only available after a full layout.'));returnconstSize(0,0);}Timeline
# Landed in version: 1.25.0-4.0.pre
In stable release: 2.0.0
References
#API documentation:
RenderBoxcomputeMinInstrinsicWidthcomputeDryLayoutgetDryLayoutperformResizeRenderWrapRenderParagraph
Relevant issues:
Relevant PRs:
Unless stated otherwise, the documentation on this site reflects Flutter 3.38.6. Page last updated on 2025-10-28.View source orreport an issue.