flutter runtime_error ai_generated true

RenderFlex children have non-zero flex but incoming height constraints are unbounded

ID: flutter/renderflex-vertical-viewport

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Flutter 3.10.0 active
Dart 3.0.0 active

Root Cause

A Column or Flex widget with Expanded children is placed inside a scrollable view (e.g., ListView, SingleChildScrollView) that does not provide a bounded height constraint.

generic

中文

带有 Expanded 子项的 Column 或 Flex 小部件被放置在未提供有界高度约束的可滚动视图(例如 ListView、SingleChildScrollView)内。

Official Documentation

https://api.flutter.dev/flutter/rendering/RenderFlex-class.html

Workarounds

  1. 85% success Wrap the Column inside an IntrinsicHeight widget to provide a bounded constraint. Example: IntrinsicHeight(child: Column(children: [Expanded(child: ...), ...]));
    Wrap the Column inside an IntrinsicHeight widget to provide a bounded constraint. Example: IntrinsicHeight(child: Column(children: [Expanded(child: ...), ...]));
  2. 90% success Use a ShrinkWrappingViewport or set the ListView's shrinkWrap: true and neverScrollableScrollPhysics: true to allow the Column to calculate its own height.
    Use a ShrinkWrappingViewport or set the ListView's shrinkWrap: true and neverScrollableScrollPhysics: true to allow the Column to calculate its own height.
  3. 80% success Replace the scrollable parent with a NonScrollableColumn or use a CustomScrollView with slivers that provide bounded constraints.
    Replace the scrollable parent with a NonScrollableColumn or use a CustomScrollView with slivers that provide bounded constraints.

中文步骤

  1. Wrap the Column inside an IntrinsicHeight widget to provide a bounded constraint. Example: IntrinsicHeight(child: Column(children: [Expanded(child: ...), ...]));
  2. Use a ShrinkWrappingViewport or set the ListView's shrinkWrap: true and neverScrollableScrollPhysics: true to allow the Column to calculate its own height.
  3. Replace the scrollable parent with a NonScrollableColumn or use a CustomScrollView with slivers that provide bounded constraints.

Dead Ends

Common approaches that don't work:

  1. Wrap the Column in a SizedBox with a fixed height 50% fail

    A fixed height may not adapt to different screen sizes and can cause overflow on smaller devices.

  2. Replace Expanded with Flexible without flex value 70% fail

    Flexible still requires a bounded constraint; the error persists if the parent is unbounded.