Skip to content
Skills Library
Design & UX · Building & coding

flutter-layout

/flutter-layout

Flutter layout and responsive design — the constraints model (constraints go down, sizes go up, parent sets position), Row/Column/Flex with Expanded and Flexible, Stack/Positioned, fixing RenderFlex overflow and 'unbounded height' / 'Vertical viewport was given unbounded height' errors, ListView.builder vs Column in SingleChildScrollView, slivers and CustomScrollView, LayoutBuilder and MediaQuery.sizeOf breakpoints, SafeArea, keyboard insets, adaptive layouts for phone/tablet/desktop/web. Use when building layouts, fixing overflow or sizing errors, or making UI responsive.

Licence
MIT
Last repository change
05.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Flutter layout and responsive design — the constraints model (constraints go down, sizes go up, parent sets position), Row/Column/Flex with Expanded and Flexible, Stack/Positioned, fixing RenderFlex overflow and 'unbounded height' / 'Vertical viewport was given unbounded height' errors, ListView.builder vs Column in SingleChildScrollView, slivers and CustomScrollView, LayoutBuilder and MediaQuery.sizeOf breakpoints, SafeArea, keyboard insets, adaptive layouts for phone/tablet/desktop/web. Use when building layouts, fixing overflow or sizing errors, or making UI responsive.

Triggers from the description

unbounded heightVertical viewport was given unbounded height
Original author description

Flutter layout and responsive design — the constraints model (constraints go down, sizes go up, parent sets position), Row/Column/Flex with Expanded and Flexible, Stack/Positioned, fixing RenderFlex overflow and 'unbounded height' / 'Vertical viewport was given unbounded height' errors, ListView.builder vs Column in SingleChildScrollView, slivers and CustomScrollView, LayoutBuilder and MediaQuery.sizeOf breakpoints, SafeArea, keyboard insets, adaptive layouts for phone/tablet/desktop/web. Use when building layouts, fixing overflow or sizing errors, or making UI responsive.

How it works

  1. The rule
  2. Row / Column
  3. Scrolling
  4. Sizing tools
  5. Stack
  6. Responsive and adaptive
  7. Safe areas and keyboard
  8. Debugging layout
Original SKILL.md headings · 74 lines, 662 words
SKILL.md preview
---
name: flutter-layout
description: "Flutter layout and responsive design — the constraints model (constraints go down, sizes go up, parent sets position), Row/Column/Flex with Expanded and Flexible, Stack/Positioned, fixing RenderFlex overflow and 'unbounded height' / 'Vertical viewport was given unbounded height' errors, ListView.builder vs Column in SingleChildScrollView, slivers and CustomScrollView, LayoutBuilder and MediaQuery.sizeOf breakpoints, SafeArea, keyboard insets, adaptive layouts for phone/tablet/desktop/web. Use when building layouts, fixing overflow or sizing errors, or making UI responsive."
license: MIT
metadata:
  author: Matiss Kalnins
  version: "0.5.0"
---

**Persona:** You reason about layout through the constraints model, never by trial-and-error wrapping in `Expanded` until the stripes go away.

## The rule

> Constraints go down. Sizes go up. The parent sets the position.

A widget can only pick a size within the constraints its parent gives it. Most layout errors come from one of two things: a child receiving **unbounded** constraints (inside a scroll view or a Row/Column's main axis) and trying to be infinitely big, or a child that's bigger than its **tight** constraints.

## Row / Column

- Children get unbounded constraints on the main axis. A `Text` that's too long overflows ("A RenderFlex overflowed by N pixels").
- Fix it with `Expanded` (fills the remaining space) or `Flexible` (may shrink, as large as its content), and for text also `overflow: .ellipsis` / `maxLines`.
- Use `spacing:` (Flutter 3.27+) instead of interleaving `SizedBox`es: `Column(spacing: spaceMD, children: [...])`, using the global `space*` constants (see `flutter-theming`). Fixed gaps between specific children are `const SizedBox(width: spaceMD)`.
- `mainAxisSize: .min` makes a Column shrink-wrap its children.
- `Spacer()` is `Expanded(child: SizedBox.shrink())`. Use it to push items apart.

## Scrolling

| Situation | Use |
| --- | --- |
| Long or unknown-length list | `ListView.builder` / `ListView.separated` (lazy) |
| Grid | `GridView.builder` with a `SliverGridDelegate` |
| Short, fixed content that might overflow on small screens | `SingleChildScrollView(child: Column(...))` |
| Mixed headers, lists, grids, collapsing app bar | `CustomScrollView` with slivers (`SliverAppBar`, `SliverList.builder`, `SliverGrid`, `SliverToBoxAdapter`) |

- **"Vertical viewport was given unbounded height"**: a `ListView` inside a `Column`. Wrap it in `Expanded`. Don't reach for `shrinkWrap: true`, which lays out every item and defeats laziness.
- Never nest a scrollable inside another scrollable on the same axis. Merge them into one `CustomScrollView` with slivers.
- Set `itemExtent` or `prototypeItem` when every row has the same height. Scrolling gets cheaper.

## Sizing tools

- `SizedBox(width:, height:)`: a fixed size, or a gap. `SizedBox.expand()` fills the parent.
- `ConstrainedBox(constraints: BoxConstraints(maxWidth: 600))`: cap content width on large screens (wrap it in `Center`).
- `AspectRatio`, `FractionallySizedBox`, `FittedBox` (scale content down to fit).
- `IntrinsicHeight`/`IntrinsicWidth` are expensive (they lay out twice). Use them only for small subtrees.
- `Container` is a convenience wrapper. Prefer the specific widget (`Padding`, `ColoredBox`, `DecoratedBox`, `SizedBox`) when you only need one feature. It's clearer and can be `const`.

## Stack

Non-positioned children size themselves according to `fit`. `Positioned` children are placed relative to the Stack's edges. The Stack sizes itself to its largest non-positioned child. A Stack with only positioned children needs a size from its parent.

## Responsive and adaptive

```dart
class const AdaptiveScaffold({super.key, required final Widget body}) extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.sizeOf(context).width;
    return switch (width) {
      < 600 => MobileLayout(body: body),      // compact
      < 840 => TabletLayout(body: body),      // medium
      _ => DesktopLayout(body: body),         // expanded
    };
  }
}
```

- Use `MediaQuery.sizeOf(context)` to adapt to the **window**. Use `LayoutBuilder` to adapt to the **space the parent gives you** (better for reusable components).
- Base breakpoints on width (Material 3 window size classes: 600 / 840 / 1200 / 1600), never on the platform (`Platform.isIOS`). A tablet in split screen is a phone-sized window.
- Navigation pattern by width: `NavigationBar` (compact) → `NavigationRail` (medium) → `NavigationDrawer` (expanded).
- Support both orientations unless the product forbids it. Test with large text scale too (see `flutter-accessibility`).

## Safe areas and keyboard

- Wrap top-level content in `SafeArea`, or use `Scaffold` + `AppBar`, which handle the top inset.
- `Scaffold(resizeToAvoidBottomInset: true)` (the default) shrinks the body when the keyboard opens. Put forms in a scroll view so focused fields stay reachable.
- Read `MediaQuery.viewInsetsOf(context).bottom` to get the keyboard height for custom bottom sheets.

## Debugging layout

- Turn on Flutter Inspector's "Show guidelines" / `debugPaintSizeEnabled = true`.
- Read the full error: it names the RenderObject and the constraints it received. Find which ancestor passed unbounded or too-tight constraints, and fix it there.

Versions

The database has no other skills named flutter-layout.

Database snapshot: 13.11.2026 · package version b68ba972ef2f (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100flutter-fix-layout-issues
    Use when fixing RenderFlex overflow errors, unbounded height and width exceptions, or ParentDataWidget layout conflicts.
  • 100flutter-fix-layout-issues
    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.
  • 100flutter-build-responsive-layout
    Use `LayoutBuilder`, `MediaQuery`, or `Expanded/Flexible` to create a layout that adapts to different screen sizes. Use when you need the UI to look good on both mobile and tablet/desktop form factors.
  • 100adaptive-layout
    Enforces adapting layout by available CONSTRAINTS/size, never device or platform checks — LayoutBuilder + MediaQuery.sizeOf/paddingOf/viewInsetsOf (not .of) for narrow rebuilds, Material 3 window size classes (compact <600, medium 600-840, expanded 840-1200, large >1200) as the…
  • 100flutter-adaptive-ui
    Build, fix, review, and validate adaptive or responsive Flutter UIs for mobile, tablet, desktop, web, large screens, foldables, and mixed input devices. Use when creating breakpoint-driven layouts, responsive navigation, adaptive dialogs/lists/grids, keyboard/mouse/touch…
  • 90responsive-adaptive
    Breakpoint rules and adaptive layout conventions for Flutter — LayoutBuilder for component decisions, MediaQuery for screen decisions, and the rule that the design artboard width is a reference and never a hardcoded target. Use this whenever writing layout code, whenever a…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.