zakariaf/flutter-skills/adaptive-layout
Claude Code and agent skill by zakariaf/flutter-skills
- community
Checking that the SKILL.md file is still in the repository.
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 breakpoint vocabulary, navigation affordance chosen by width (NavigationBar → NavigationRail → NavigationDrawer), list-detail single-pane-vs-two-pane, readable max-width via ConstrainedBox, Flexible/Expanded/FractionallySizedBox over fixed widths, SafeArea + display cutouts + keyboard insets, never lock orientation, foldable/hinge awareness via MediaQuery.displayFeatures, and golden-matrix verification across sizes. Use when building responsive or adaptive UI, tablet/desktop/foldable support, master-detail or two-pane screens, a NavigationRail-vs-BottomNav shell, breakpoints, LayoutBuilder, MediaQuery sizing, SafeArea/cutouts, or fixing overflow at large widths.
Install
npx vskill@latest install zakariaf/flutter-skills/adaptive-layoutSKILL.md
The same SKILL.md was published earlier as zakariaf/flutter-skills/adaptive-layout.
Adaptive Layout
Adapt to the space you are given, never to the device you think you are on. A phone in a foldable's front display, a resized desktop window, and a tablet in split-screen all defeat Platform.isX checks — but they all report their real constraints. Branch on width, not hardware.
Read the reference for the task at hand:
references/window-size-classes.md— the Material 3 window size-class breakpoints as a shared vocabulary, theWindowSizeClassenum pattern,MediaQuery.sizeOf/paddingOf/viewInsetsOfvs.of, readable max-width, SafeArea and display cutouts, keyboard insets, orientation, foldable hinge awareness.references/list-detail-and-navigation.md— single-pane-navigate vs side-by-side two-pane, choosing the navigation affordance by width and coordinating with the go_router shell, keeping selection state in a Notifier so both panes agree.
Run scripts/check_adaptive.sh before a PR.
Non-negotiable rules
- Adapt by constraints/size, never by device or platform. No
Platform.isAndroid/Platform.isIOS/kIsWebto pick a layout. UseLayoutBuilder(local box constraints) orMediaQuery.sizeOf(context)(window size). WHY: a resized window, split-screen, and foldable all break device checks; constraints are always true.
- Use the Material 3 window size classes as the breakpoint vocabulary. Compact
<600, medium600–840, expanded840–1200, large1200–1600, extra-large≥1600(logical px width). WHY: these are STANDARD structural breakpoints (not design tokens); one shared enum keeps every screen's breakpoints identical.
- Read the narrowest MediaQuery aspect: `sizeOf` / `paddingOf` / `viewInsetsOf` / `viewPaddingOf`, not `MediaQuery.of(context)`. WHY:
.ofsubscribes the widget to EVERY MediaQuery change (keyboard, rotation, text scale); the aspect getters rebuild only when that one field changes — seeflutter-performance.
- Pick the navigation affordance by width, not by a per-screen guess.
NavigationBar(compact) →NavigationRail(medium/expanded) →NavigationDrawer(large). Decide once in the shell. WHY: mixing affordances across screens disorients; one width→affordance map is consistent by construction. Coordinate withnavigation-and-routing'sStatefulShellRoute.
- List-detail collapses to one pane on compact and splits on expanded. Compact: the list navigates to a detail route. Expanded: list and detail sit side-by-side; selection is shared state. WHY: two panes on a phone are unreadable; one pane on a desktop wastes 70% of the width.
- Never lock orientation (
SystemChrome.setPreferredOrientationsto force portrait). WHY: it breaks tablets, foldables, and accessibility mounts. Let the size classes handle both orientations.
- Constrain readable content with a max width; use `Flexible`/`Expanded`/`FractionallySizedBox`, not fixed pixel widths, for top-level regions. WHY: full-width body text on a wide screen is unreadable (~40–75 chars/line is legible); fixed region widths overflow or leave dead space.
- Wrap edge content in `SafeArea` and respect display cutouts + keyboard insets. Read cutouts/system bars via
MediaQuery.paddingOf/viewPaddingOf; the keyboard viaMediaQuery.viewInsetsOf. WHY: notches, punch-holes, and the on-screen keyboard occlude content that ignores insets.
- Never assume a fixed cell/row height. Large text scale can double a cell's height; let content size itself. WHY: a hardcoded
SizedBox(height: 48)clips at 200% text scale — seeaccessibility-as-codeandwidget-composition.
- Verify across sizes with a golden matrix, not one device. Snapshot each adaptive screen at compact/medium/expanded (+ largest text, LTR/RTL). WHY: adaptive bugs only appear at the breakpoint you did not open — see
widget-golden-and-a11y-testing.
Size classes as one shared enum
Define the breakpoints once; every screen reads the same map.
Prefer LayoutBuilder when the decision depends on the LOCAL box (a widget inside a split view, a card grid), and MediaQuery.sizeOf when it depends on the whole window (the top-level shell).
Readable width and flexible regions
Insets, cutouts, keyboard, foldables
Wrap the outermost interactive region in SafeArea; opt specific edges out (bottom: false) when a NavigationBar or scrolling body should reach the edge.
Navigation affordance by width
See examples/adaptive_scaffold.dart for the full shell and examples/list_detail_pane.dart for the two-pane pattern.
Anti-patterns
if (Platform.isIOS) ... else ...to choose a layout. Branch onMediaQuery.sizeOf(context).width.MediaQuery.of(context).size.width— subscribes to every MediaQuery change. UseMediaQuery.sizeOf(context).SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])to dodge landscape layout. Support both.Container(width: 375)orSizedBox(width: 320)sizing a top-level pane. UseExpanded/Flexible/FractionallySizedBox/ConstrainedBox.- A
bool isTablet = MediaQuery.of(context).size.shortestSide > 600flag threaded everywhere. Compute aWindowSizeClassfrom width at the shell. - Two panes shown on compact width, forcing horizontal scroll. Collapse to one pane and navigate.
- Full-width paragraphs on desktop with no max-width. Cap the measure.
- Assuming the keyboard is hidden — content jumps under it. Pad by
MediaQuery.viewInsetsOf(context).bottom.
Definition of done
- No
Platform.is*/kIsWeb/dart:ioused to select a layout (platform-specific plugins are fine). - Breakpoints come from the shared
WindowSizeClasshelper, not ad-hoc numbers scattered per screen. - MediaQuery is read via
sizeOf/paddingOf/viewInsetsOf/viewPaddingOf, not.of. - Navigation affordance is chosen by width in ONE place (the shell), coordinated with
navigation-and-routing. - List-detail screens collapse to one pane on compact and split on expanded, sharing selection state.
- No fixed pixel widths on top-level regions; readable content is max-width capped.
- Orientation is not locked; edge content uses
SafeArea; keyboard insets are respected. - Golden matrix covers compact/medium/expanded (+ largest text, RTL).
scripts/check_adaptive.shpasses.
Related skills
widget-composition— structural layout primitives, computed sizing, edge-to-edge vs SafeArea, never-fixed cell heights.navigation-and-routing— theStatefulShellRoutethis shell renders; width picks the chrome, routes pick the branch.flutter-performance— whysizeOf/selectbeat.offor rebuild scope.accessibility-as-code— large text scale interacts with every adaptive cell.widget-golden-and-a11y-testing— the device × text-scale × RTL golden matrix that proves adaptivity.state-management-riverpod— where shared list-detail selection lives.
References
- Material 3 layout / window size classes: https://m3.material.io/foundations/layout/applying-layout/window-size-classes
- Adaptive & responsive design (Flutter): https://docs.flutter.dev/ui/adaptive-responsive
MediaQueryAPI (aspect getters): https://api.flutter.dev/flutter/widgets/MediaQuery-class.htmlLayoutBuilder: https://api.flutter.dev/flutter/widgets/LayoutBuilder-class.htmlNavigationRail: https://api.flutter.dev/flutter/material/NavigationRail-class.htmlDisplayFeature/ foldables: https://api.flutter.dev/flutter/dart-ui/DisplayFeature-class.html
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/adaptive-layout/SKILL.md
Popularity
- Repository stars
- 22
- Repository forks
- 4
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/flutter-skills/adaptive-layout)