flutter-layout▌
flutter/skills · updated Apr 8, 2026
Build responsive Flutter layouts by composing widgets, managing constraints, and adapting to screen sizes.
- ›Provides a decision tree for selecting the right base layout widget (Row, Column, Stack, ListView, GridView, CustomScrollView) based on content dimensionality, overlap, scrolling, and responsiveness needs
- ›Enforces Flutter's core constraint system: constraints flow down, sizes flow up, parents set position; includes ConstrainedBox patterns for forcing specific dimensions
- ›Implemen
Goal
Constructs robust, responsive Flutter user interfaces by composing layout widgets, managing constraints, and implementing adaptive design patterns. Assumes the target environment has the Flutter SDK installed and the user is familiar with Dart syntax and state management fundamentals.
Instructions
-
Determine Layout Strategy (Decision Logic) Analyze the UI requirements and select the appropriate base layout widgets using the following decision tree:
- Is the content strictly 1-Dimensional?
- Horizontal arrangement -> Use
Row. - Vertical arrangement -> Use
Column.
- Horizontal arrangement -> Use
- Does the content need to overlap (Z-axis)?
- Yes -> Use
StackwithPositionedorAlignchildren.
- Yes -> Use
- Does the content exceed the screen size?
- Yes, 1D list -> Use
ListView. - Yes, 2D grid -> Use
GridView. - Yes, custom scroll effects -> Use
CustomScrollViewwith Slivers.
- Yes, 1D list -> Use
- Does the layout need to adapt to screen size changes?
- Yes -> Use
LayoutBuilderorMediaQuery.
- Yes -> Use
- Is the content strictly 1-Dimensional?
-
Apply the Golden Rule of Constraints Enforce Flutter's core layout rule: Constraints go down. Sizes go up. Parent sets position. When a widget requires a specific size, ensure its parent allows it. Use
ConstrainedBoxto inject specific constraints, but remember it only adds to the parent's constraints.// Example: Forcing a specific size within a flexible parent Center( child: ConstrainedBox( constraints: const BoxConstraints( minWidth: 70, minHeight: 70, maxWidth: 150, maxHeight: 150, ), child: Container( color: Colors.blue, width: 1000, // Will be constrained to 150 (max) height: 10, // Will be constrained to 70 (min) ), ), ) -
Implement Adaptive Layouts For screens that must support both mobile and tablet/desktop form factors, implement a
LayoutBuilderto branch the UI logic based on available width.class AdaptiveScreen extends StatelessWidget { const AdaptiveScreen({super.key}); Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: LayoutBuilder( builder: (context, constraints) { if (constraints.maxWidth > 600) { return _buildWideLayout(); } else { return _buildNarrowLayout(); } }, ), ), ); } Widget _buildWideLayout() { return Row( children: [ const SizedBox(width: 250, child: Placeholder()), // Sidebar Container(width: 1, color: Colors.grey), // Divider const Expanded(child: Placeholder()), // Main Content ], ); } Widget _buildNarrowLayout() { return const Column( children: [ Expanded(child: Placeholder()), // Main Content ], ); } } -
Compose Flex Layouts (Rows and Columns) When using
RoworColumn, manage child sizing usingExpanded(forces child to fill available space) orFlexible(allows child to be smaller than available space).Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, children: [ const Icon(Icons.star), Expanded( flex: 2, child: Container(color: Colors.red, height: 50), ), Flexible( flex: 1, child: Container(color: Colors.blue, height: 50), ), ], ) -
Gather Context STOP AND ASK THE USER: "What are the target devices (e.g., mobile, tablet, web) and specific breakpoint widths required for this layout?"
-
Validate-and-Fix: Handle Unbounded Constraints Verify that no
ExpandedorFlexiblewidgets are placed inside unbounded parents (likeListVieworSingleChildScrollView). If a RenderFlex overflow occurs, implement the following fix:// INCORRECT: Expanded inside a scrollable view causes unbounded height errors. // SingleChildScrollView(child: Column(children: [Expanded(child: Container())])) // CORRECT: Use a bounded height or remove Expanded. // Alternatively, use CustomScrollView with SliverFillRemaining: CustomScrollView( slivers: [ SliverToBoxAdapter(child: HeaderWidget()), SliverFillRemaining( hasScrollBody: false, child: ExpandedContentWidget(), ), ], )
Constraints
- Always wrap top-level screen content in a
SafeAreato prevent overlap with system UI. - Never place an
ExpandedorFlexiblewidget inside a parent that provides unbounded constraints (e.g.,SingleChildScrollView,ListView, orRowinside a horizontally scrolling view). - Do not use
Containersolely for padding; use thePaddingwidget for better performance. - Assume the user is using Material 3 (
useMaterial3: trueis default).
Ratings
4.8★★★★★71 reviews- ★★★★★Arya Thompson· Dec 24, 2024
Registry listing for flutter-layout matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Min Robinson· Dec 20, 2024
flutter-layout reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Amina Flores· Dec 20, 2024
Keeps context tight: flutter-layout is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Shikha Mishra· Dec 16, 2024
flutter-layout reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Amina Garcia· Dec 16, 2024
Useful defaults in flutter-layout — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Nikhil Mensah· Dec 12, 2024
Registry listing for flutter-layout matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Arya Garcia· Dec 8, 2024
flutter-layout is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Evelyn Malhotra· Nov 27, 2024
flutter-layout is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Evelyn Jain· Nov 15, 2024
Useful defaults in flutter-layout — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Naina Huang· Nov 11, 2024
I recommend flutter-layout for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
showing 1-10 of 71