LayoutBuilder Does Not Support Returning Intrinsic Dimensions
You put auto-sizing text in a Table cell, hot-reloaded, and got this: LayoutBuilder does not support returning intrinsic dimensions. Calculating the intrinsic dimensions would require running the layout callback speculatively, which might mutate the live render object tree. at _RenderLayoutBuilder.computeMaxIntrinsicHeight The stack trace is long, it points at framework code you did not write,…
The LayoutBuilder widget in Flutter does not support returning intrinsic dimensions, such as height or width. Attempting to do so results in an error message stating that LayoutBuilder cannot support returning intrinsic dimensions because it may mutate the live render object tree. This limitation exists due to the fundamental difference in how Flutter's layout protocol works compared to other layout systems like CSS tables.
Intrinsic dimensions are necessary in some cases, such as when matching children to the tallest one or when aligning text baselines. Flutter provides an alternative protocol to handle these scenarios, which involves a hypothetical question to the child widget: "If I gave you 200 pixels of width, how tall would you want to be?" This question is answered using the computeMaxIntrinsicHeight method, and the key point is that it is a pure computation with no side effects.
The child widget is asked to predict a size for constraints it has not been given, and this computation must be performed without touching the render tree.
The LayoutBuilder widget exists to run your code with the constraints as an argument, but it cannot answer intrinsic queries because it would require running the builder callback with a specific set of constraints and potentially mutating the render tree during a speculative query. This could happen several times as the parent searches for a fit, which is not allowed by Flutter's single-pass, linear layout protocol.
The architecture is designed to avoid speculative builder invocations, which would require a second pass through user code – something the framework is intentionally designed to avoid for performance reasons.
This limitation often catches developers by surprise, especially when using a Table widget with auto-sizing text. The Table widget sizes a column to fit its widest cell by default, and it needs to know the height of each cell before deciding what constraints to give them. If you put auto-sizing text in a Table cell and hot-reload, you might encounter the error message "LayoutBuilder does not support returning intrinsic dimensions."
The error is the framework's way of protecting you from potentially corrupting your layout during speculative queries.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.