flutter-fix-layout-issues
Diagnose and fix Flutter layout constraint violations (RenderFlex overflow, unbounded height/width, ParentData misuse). Use when encountering layout exceptions, yellow-black overflow stripes, or red error screens.
What this skill does
## Contents
- [Constraint Model](#constraint-model)
- [Error Signature Catalog](#error-signature-catalog)
- [Resolution Patterns](#resolution-patterns)
- [Workflow: Fixing Layout Issues](#workflow-fixing-layout-issues)
- [Examples](#examples)
## Constraint Model
Flutter layout operates on a strict negotiation rule:
> **Constraints go down. Sizes go up. Parent sets position.**
1. A parent widget passes **constraints** (min/max width and height) to its child.
2. The child determines its own **size** within those constraints.
3. The parent decides the child's **position**.
Layout errors occur when this negotiation fails — typically when a parent provides **unbounded** constraints (infinite width or height) and the child attempts to expand infinitely.
## Error Signature Catalog
| Error Message | Root Cause | Quick Fix |
|---|---|---|
| `Vertical viewport was given unbounded height` | Scrollable (`ListView`, `GridView`) inside unconstrained vertical parent (`Column`) | Wrap in `Expanded` or `SizedBox(height: ...)` |
| `An InputDecorator...cannot have an unbounded width` | `TextField` inside unconstrained horizontal parent (`Row`) | Wrap in `Expanded` |
| `A RenderFlex overflowed by X pixels` | Child exceeds parent's allocated constraints | Wrap in `Expanded`, `Flexible`, or use `overflow: TextOverflow.ellipsis` |
| `Incorrect use of ParentData widget` | `Expanded` outside `Flex`, `Positioned` outside `Stack` | Move widget to be direct child of correct parent |
| `RenderBox was not laid out` | **Cascading error** — look upstream in stack trace | Fix the primary constraint error above it |
**Rule**: Always fix the **first** error in the stack trace. `RenderBox was not laid out` is almost always a cascading side effect.
## Resolution Patterns
### Decision Tree
```
Error detected
├── Contains "unbounded height"?
│ └── Wrap scrollable child in Expanded or SizedBox
├── Contains "unbounded width"?
│ └── Wrap TextField/InputDecorator in Expanded
├── Contains "RenderFlex overflowed"?
│ ├── Text overflow?
│ │ └── Add overflow: TextOverflow.ellipsis + Expanded wrapper
│ └── Widget overflow?
│ └── Wrap in Expanded or Flexible
├── Contains "ParentData"?
│ └── Ensure Expanded is direct child of Row/Column/Flex
│ Ensure Positioned is direct child of Stack
└── Contains "RenderBox was not laid out"?
└── IGNORE — fix the error above this one
```
### Expanded vs Flexible vs SizedBox
| Widget | Behavior | Use When |
|---|---|---|
| `Expanded` | Forces child to fill ALL remaining space | Child should stretch to fill |
| `Flexible` | Allows child to be SMALLER than remaining space | Child has natural size but shouldn't overflow |
| `SizedBox` | Provides absolute fixed constraints | You know the exact dimension needed |
| `ConstrainedBox` | Sets min/max constraints | You need bounded flexibility |
## Workflow: Fixing Layout Issues
### Task Progress
- [ ] **Step 1**: Run app in debug mode — capture the exact exception in console.
- [ ] **Step 2**: Identify the **primary** error message (ignore cascading `RenderBox was not laid out`).
- [ ] **Step 3**: Match error against the Error Signature Catalog above.
- [ ] **Step 4**: Apply the conditional fix:
- If `unbounded height` → wrap scrollable in `Expanded` or `SizedBox`
- If `unbounded width` → wrap input in `Expanded`
- If `RenderFlex overflowed` → wrap in `Expanded` or `Flexible`
- If `ParentData` → restructure widget tree
- [ ] **Step 5**: Hot reload → verify the error is resolved.
- [ ] **Step 6**: If new layout errors appear → repeat from Step 2.
## Examples
### Fixing Unbounded Height (ListView in Column)
**Before (throws `Vertical viewport was given unbounded height`):**
```dart
Column(
children: <Widget>[
const Text('Header'),
ListView(
children: const <Widget>[
ListTile(title: Text('Item 1')),
ListTile(title: Text('Item 2')),
],
),
],
)
```
**After (resolved):**
```dart
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)
**Before (throws `An InputDecorator...cannot have an unbounded width`):**
```dart
Row(
children: [
const Icon(Icons.search),
TextField(),
],
)
```
**After (resolved):**
```dart
Row(
children: [
const Icon(Icons.search),
Expanded(
child: TextField(),
),
],
)
```
### Fixing RenderFlex Overflow (Text in Row)
**Before (throws `A RenderFlex overflowed by X pixels on the right`):**
```dart
Row(
children: [
const Icon(Icons.info),
Text('This is a very long text that will overflow the screen width'),
],
)
```
**After (resolved):**
```dart
Row(
children: [
const Icon(Icons.info),
Expanded(
child: Text(
'This is a very long text that will overflow the screen width',
overflow: TextOverflow.ellipsis,
),
),
],
)
```
### Fixing ParentData Misuse
**Before (throws `Incorrect use of ParentData widget`):**
```dart
// Expanded must be a DIRECT child of Row/Column/Flex
Container(
child: Expanded( // WRONG: Expanded not inside a Flex
child: Text('Hello'),
),
)
```
**After (resolved):**
```dart
Row(
children: [
Expanded( // OK: Direct child of Row (a Flex widget)
child: Text('Hello'),
),
],
)
```
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.