PluginBench
Skill
Pass
Audit score 90

flutter-fix-layout-issues

flutter/agent-plugins

Diagnose and fix Flutter layout errors like overflows and unbounded constraints using constraint-violation patterns.

What is flutter-fix-layout-issues?

Resolves Flutter layout failures (RenderFlex overflows, unbounded height/width) by identifying constraint violations and applying targeted fixes. Use when encountering layout exception messages in debug mode.

  • Diagnoses constraint violation errors: unbounded height, unbounded width, RenderFlex overflow, and incorrect ParentData widget placement
  • Provides a systematic workflow to identify primary error messages and apply conditional fixes
  • Wraps problematic widgets (ListView, TextField, Text) in Expanded or Flexible to constrain them within parent bounds
  • Handles cascading errors by filtering out secondary "RenderBox was not laid out" messages to find root causes
  • Includes before/after code examples for common layout patterns

How to install flutter-fix-layout-issues

npx skills add https://github.com/flutter/agent-plugins --skill flutter-fix-layout-issues
Claude Code
Cursor
Windsurf
Cline

How to use flutter-fix-layout-issues

  1. 1.Run your Flutter application in debug mode and capture the exact layout exception message from the console
  2. 2.Identify the primary error type (unbounded height, unbounded width, RenderFlex overflow, or ParentData misuse)
  3. 3.Match your error to the conditional fix: wrap scrollables in Expanded for height, wrap text inputs in Expanded for width, wrap overflowing children in Expanded or Flexible
  4. 4.Apply the fix by modifying your Dart widget tree (see Examples section for patterns)
  5. 5.Execute Flutter hot reload to verify the error is resolved
  6. 6.Inspect the UI to confirm red/grey error screens or yellow/black stripes are gone; repeat if new errors appear

Use cases

Good for
  • Fix "Vertical viewport was given unbounded height" when ListView or GridView is placed in an unconstrained Column
  • Resolve "An InputDecorator cannot have an unbounded width" when TextField is in an unconstrained Row
  • Eliminate "RenderFlex overflowed" yellow/black warning stripes by constraining oversized children
  • Correct "Incorrect use of ParentData widget" errors by repositioning Expanded, Flexible, or Positioned widgets
  • Debug layout cascades by identifying the primary constraint violation in the exception stack
Who it's for
  • Flutter developers fixing layout runtime errors
  • Mobile app developers working with complex UI hierarchies
  • Teams using Dart and Flutter MCP tools for automated debugging

flutter-fix-layout-issues FAQ

What does "Constraints go down. Sizes go up. Parent sets position" mean?

This is Flutter's layout rule: parents pass size constraints to children (down), children report their desired size (up), and parents position children within their allocated space. Layout errors occur when this negotiation breaks—typically when a child receives infinite constraints or requests more space than available.

Why do I see "RenderBox was not laid out" errors?

This is a cascading side-effect error, not the root cause. Look further up the stack trace for the primary constraint violation (usually unbounded height/width). Fixing the primary error will resolve the RenderBox error.

When should I use Expanded vs. Flexible?

Use Expanded to force a child to fill remaining space and consume all available constraints. Use Flexible to allow a child to be smaller than allocated space. For most layout fixes, Expanded is the right choice.

Can I use SizedBox instead of Expanded for unbounded height?

Yes. SizedBox with a fixed height works for unbounded height errors, but Expanded is more flexible because it adapts to different screen sizes. Use SizedBox only when you need an absolute fixed height.

How do I know if my layout fix is correct?

After applying the fix and hot reloading, the red/grey error screen or yellow/black overflow stripes should disappear. The UI should render without layout exceptions. If new errors appear, repeat the diagnostic workflow.

Full instructions (SKILL.md)

Source of truth, from flutter/agent-plugins.


name: flutter-fix-layout-issues description: Fixes Flutter layout errors (overflows, unbounded constraints) using Dart and Flutter MCP tools. Use when addressing "RenderFlex overflowed", "Vertical viewport was given unbounded height", or similar layout issues. metadata: model: models/gemini-3.1-pro-preview last_modified: Tue, 21 Apr 2026 19:45:59 GMT

Resolving Flutter Layout Errors

Contents

Constraint Violation Diagnostics

Flutter layout operates on a strict rule: Constraints go down. Sizes go up. Parent sets position. Layout errors occur when this negotiation fails, typically due to unbounded constraints or unconstrained children.

Diagnose layout failures using the following error signatures:

  • "Vertical viewport was given unbounded height": Triggered when a scrollable widget (ListView, GridView) is placed inside an unconstrained vertical parent (Column). The parent provides infinite height, and the child attempts to expand infinitely.
  • "An InputDecorator...cannot have an unbounded width": Triggered when a TextField or TextFormField is placed inside an unconstrained horizontal parent (Row). The text field attempts to determine its width based on infinite available space.
  • "RenderFlex overflowed": Triggered when a child of a Row or Column requests a size larger than the parent's allocated constraints. Visually indicated by yellow and black warning stripes.
  • "Incorrect use of ParentData widget": Triggered when a ParentDataWidget is not a direct descendant of its required ancestor. (e.g., Expanded outside a Flex, Positioned outside a Stack).
  • "RenderBox was not laid out": A cascading side-effect error. Ignore this and look further up the stack trace for the primary constraint violation (usually an unbounded height/width error).

Layout Error Resolution Workflow

Copy and use this checklist to systematically resolve layout constraint violations.

Task Progress

  • Run the application in debug mode to capture the exact layout exception in the console.
  • Identify the primary error message (ignore cascading "RenderBox was not laid out" errors).
  • Apply the conditional fix based on the specific error type:
    • If "Vertical viewport was given unbounded height": Wrap the scrollable child (ListView, GridView) in an Expanded widget to consume remaining space, or wrap it in a SizedBox to provide an absolute height constraint.
    • If "An InputDecorator...cannot have an unbounded width": Wrap the TextField or TextFormField in an Expanded or Flexible widget.
    • If "RenderFlex overflowed": Constrain the overflowing child by wrapping it in an Expanded widget (to force it to fit) or a Flexible widget (to allow it to be smaller than the allocated space).
    • If "Incorrect use of ParentData widget": Move the ParentDataWidget to be a direct child of its required parent. Ensure Expanded/Flexible are direct children of Row/Column/Flex. Ensure Positioned is a direct child of Stack.
  • Execute Flutter hot reload.
  • Run validator -> review errors -> fix: Inspect the UI to verify the red/grey error screen or yellow/black overflow stripes are resolved. If new layout errors appear, repeat the workflow.

Examples

Fixing Unbounded Height (ListView in Column)

Input (Error State):

// Throws "Vertical viewport was given unbounded height"
Column(
  children: <Widget>[
    const Text('Header'),
    ListView(
      children: const <Widget>[
        ListTile(title: Text('Item 1')),
        ListTile(title: Text('Item 2')),
      ],
    ),
  ],
)

Output (Resolved State):

// Wrap ListView in Expanded to constrain its height to the remaining Column space
Column(
  children: <Widget>[
    const Text('Header'),
    Expanded(
      child: ListView(
        children: const <Widget>[
          ListTile(title: Text('Item 1')),
          ListTile(title: Text('Item 2')),
        ],
      ),
    ),
  ],
)

Fixing Unbounded Width (TextField in Row)

Input (Error State):

// Throws "An InputDecorator...cannot have an unbounded width"
Row(
  children: [
    const Icon(Icons.search),
    TextField(), 
  ],
)

Output (Resolved State):

// Wrap TextField in Expanded to constrain its width to the remaining Row space
Row(
  children: [
    const Icon(Icons.search),
    Expanded(
      child: TextField(),
    ),
  ],
)

Fixing RenderFlex Overflow

Input (Error State):

// Throws "A RenderFlex overflowed by X pixels on the right"
Row(
  children: [
    const Icon(Icons.info),
    const Text('This is a very long text string that will definitely overflow the available screen width and cause a RenderFlex error.'),
  ],
)

Output (Resolved State):

// Wrap the Text widget in Expanded to force it to wrap within the available constraints
Row(
  children: [
    const Icon(Icons.info),
    Expanded(
      child: const Text('This is a very long text string that will definitely overflow the available screen width and cause a RenderFlex error.'),
    ),
  ],
)