flutter-fix-layout-issues
작성자: flutter
Flutter 레이아웃 오류(오버플로우, 무제한 제약 조건)를 Dart 및 Flutter MCP 도구를 사용하여 수정합니다. "RenderFlex overflowed", "Vertical…" 문제를 해결할 때 사용하세요.
npx skills add https://github.com/flutter/skills --skill flutter-fix-layout-issuesResolving 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
TextFieldorTextFormFieldis 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
RoworColumnrequests 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
ParentDataWidgetis not a direct descendant of its required ancestor. (e.g.,Expandedoutside aFlex,Positionedoutside aStack). - "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 anExpandedwidget to consume remaining space, or wrap it in aSizedBoxto provide an absolute height constraint. - If "An InputDecorator...cannot have an unbounded width": Wrap the
TextFieldorTextFormFieldin anExpandedorFlexiblewidget. - If "RenderFlex overflowed": Constrain the overflowing child by wrapping it in an
Expandedwidget (to force it to fit) or aFlexiblewidget (to allow it to be smaller than the allocated space). - If "Incorrect use of ParentData widget": Move the
ParentDataWidgetto be a direct child of its required parent. EnsureExpanded/Flexibleare direct children ofRow/Column/Flex. EnsurePositionedis a direct child ofStack.
- If "Vertical viewport was given unbounded height": Wrap the scrollable child (
- 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.'),
),
],
)
flutter의 다른 스킬
dart-modern-features
flutter
현대화를 위한 후보를 찾으려면:
official
dart-log-failure-parser
flutter
Dart 및 Flutter 테스트 로그에서 실패를 파싱합니다.
official
find-release
flutter
주어진 커밋이 포함된 가장 낮은 Dart 및 Flutter 릴리스를 찾는 스킬입니다. 사용자가 Flutter나 Dart에서 커밋이 언제 포함되었는지 물을 때 이 스킬을 사용하세요…
official
flutter-pr-checks-finder
flutter
Flutter PR에서 실패한 검사를 찾고 해당 LUCI 로그 URL을 찾습니다.
official
rebuilding-flutter-tool
flutter
Flutter 도구와 CLI를 재빌드합니다. 사용자가 Flutter 도구나 CLI를 컴파일, 업데이트, 재생성 또는 재빌드하도록 요청할 때 사용하세요.
official
upgrade-browser
flutter
Flutter Web Engine 및/또는 Framework 테스트에서 브라우저 버전(Chrome 또는 Firefox)을 업그레이드합니다. Chrome 또는 Firefox를 최신 버전으로 롤 또는 업그레이드하라는 요청을 받을 때 사용하세요.
official
create-catalog-item
flutter
사용자가 JSON 스키마 정의를 기반으로 새 CatalogItem, 데이터 클래스 및/또는 위젯 클래스를 생성하도록 요청할 때 이 스킬을 사용하세요.
official
genui-helper
flutter
이 스킬은 genui 저장소에 특화된 워크플로우와 모범 사례를 제공합니다.
official