Flutter's Align widget ignores child size in Wrap unless widthFactor is set
In Flutter, placing an Align widget inside a Wrap causes it to expand to the full line width rather than hugging its child, because Wrap passes bounded — not unbounded — constraints to its children. The root cause lies in RenderPositionedBox, where shrink-wrapping only activates if widthFactor is non-null or maxWidth is infinite, and Wrap satisfies neither condition by default. Setting widthFactor: 1.0 on the Align widget forces it to size itself to the child's dimensions, shrinking from 800px to 28px for a two-character label in tests. An alternative fix is wrapping the child in IntrinsicWidth, though that approach is more useful when multiple siblings need to share a common width. For single-widget cases, widthFactor: 1.0 is the simpler and more performant solution.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.



Discussion (0)
Log in to join the discussion and vote.
Log in