flutter-layout
/flutter-layout
Porządkuje układ i responsywność we Flutter, naprawia błędy przepełnienia i nieograniczonej wysokości oraz dobiera slivery.
- Autor
- Dee9975 ↗
- Repozytorium
- cc-skills-flutter ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 05.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 05.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Porządkuje układ i responsywność we Flutter, naprawia błędy przepełnienia i nieograniczonej wysokości oraz dobiera slivery.
Wyzwalacze z opisu
Oryginalny opis (EN)
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.
Jak działa
- The rule
- Row / Column
- Scrolling
- Sizing tools
- Stack
- Responsive and adaptive
- Safe areas and keyboard
- Debugging layout
Podgląd SKILL.md
---
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.
Wersje
W bazie nie ma innych skilli o nazwie flutter-layout.
Migawka bazy z 13.11.2026 · wersja paczki b68ba972ef2f (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100flutter-fix-layout-issues
Naprawia błędy przepełnienia RenderFlex, wyjątki nieograniczonej wysokości i szerokości oraz konflikty ParentDataWidget we Flutterze. - 100flutter-fix-layout-issues
Naprawia błędy układu we Flutterze, takie jak przepełnienie RenderFlex i nieograniczona wysokość viewportu, z użyciem narzędzi Dart i Flutter MCP. - 100flutter-build-responsive-layout
Buduje układy dopasowujące się do rozmiaru ekranu z użyciem LayoutBuilder, MediaQuery oraz Expanded i Flexible, tak by UI dobrze wyglądał na telefonie, tablecie i desktopie. - 100adaptive-layout
Wymusza układ zależny od dostępnych ograniczeń rozmiaru we Flutterze: LayoutBuilder, MediaQuery.sizeOf, klasy okien Material 3, wybór nawigacji według szerokości i układ lista-szczegóły. - 100flutter-adaptive-ui
Buduje, naprawia i weryfikuje adaptacyjne interfejsy Flutter na mobile, tablet, desktop, web i składane ekrany: breakpointy, nawigacja, MediaQuery, LayoutBuilder oraz obsługa myszy, klawiatury i dotyku. - 90responsive-adaptive
Podaje zasady breakpointów dla Fluttera: LayoutBuilder dla komponentów, MediaQuery dla ekranu, bez sztywnej szerokości artboardu.