flutter
runtime_error
ai_generated
true
RenderBox was not laid out: RenderViewport#abcde needs to have a 'size' but its constraints are 'BoxConstraints(unconstrained)'
ID: flutter/rendering-box-height-nan
90%Fix Rate
87%Confidence
1Evidence
2023-05-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.0.0 | active | — | — | — |
| 3.10.0 | active | — | — | — |
| 3.16.0 | active | — | — | — |
| 3.22.0 | active | — | — | — |
Root Cause
A scrollable widget (e.g., ListView, GridView) is placed inside a Column or Row without being given explicit constraints, causing infinite height.
generic中文
可滚动小部件(例如 ListView、GridView)放置在 Column 或 Row 中,未获得显式约束,导致高度无限。
Official Documentation
https://api.flutter.dev/flutter/rendering/RenderViewport-class.htmlWorkarounds
-
90% success Wrap the scrollable widget in an Expanded or Flexible inside a Column or Row to give it bounded constraints.
Wrap the scrollable widget in an Expanded or Flexible inside a Column or Row to give it bounded constraints.
-
85% success Use a CustomScrollView with slivers instead of nesting a ListView in a Column.
Use a CustomScrollView with slivers instead of nesting a ListView in a Column.
-
75% success Set a specific height constraint using SizedBox or Container with a height, but ensure it's enough for content.
Set a specific height constraint using SizedBox or Container with a height, but ensure it's enough for content.
中文步骤
Wrap the scrollable widget in an Expanded or Flexible inside a Column or Row to give it bounded constraints.
Use a CustomScrollView with slivers instead of nesting a ListView in a Column.
Set a specific height constraint using SizedBox or Container with a height, but ensure it's enough for content.
Dead Ends
Common approaches that don't work:
-
40% fail
If content exceeds the fixed height, the ListView will overflow or clip; not adaptive.
-
35% fail
Expanded requires bounded constraints; if parent is unconstrained, it still fails.
-
25% fail
Does not give the ListView bounded constraints; the Column still tries to size itself to the ListView's infinite height.