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

Also available as: JSON · Markdown · 中文
90%Fix Rate
87%Confidence
1Evidence
2023-05-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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.html

Workarounds

  1. 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.
  2. 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.
  3. 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.

中文步骤

  1. Wrap the scrollable widget in an Expanded or Flexible inside a Column or Row to give it bounded constraints.
  2. Use a CustomScrollView with slivers instead of nesting a ListView in a Column.
  3. 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:

  1. 40% fail

    If content exceeds the fixed height, the ListView will overflow or clip; not adaptive.

  2. 35% fail

    Expanded requires bounded constraints; if parent is unconstrained, it still fails.

  3. 25% fail

    Does not give the ListView bounded constraints; the Column still tries to size itself to the ListView's infinite height.