flutter-building-layouts
flutter/agent-plugins · 10.6k installs · 3.1K stars
Skill
Install
npx -y skills add flutter/agent-plugins --skill flutter-building-layouts --agent claude-codeRun in a terminal. Claude loads the skill when a task calls for it. Check the repo's README before you run it.
Files
Architecting Flutter Layouts
Contents
- Core Layout Principles
- Structural Widgets
- Adaptive and Responsive Design
- Workflow: Implementing a Complex Layout
- Examples
Core Layout Principles
Master the fundamental Flutter layout rule: Constraints go down. Sizes go up. Parent sets position.
- Pass Constraints Down: Always pass constraints (minimum/maximum width and height) from the parent Widget to its children. A Widget cannot choose its own size independently of its parent's constraints.
- Pass Sizes Up: Calculate the child Widget's desired size within the given constraints and pass this size back up to the parent.
- Set Position via Parent: Define the
xandycoordinates of a child Widget exclusively within the parent Widget. Children do not know their own position on the screen. - Avoid Unbounded Constraints: Never pass unbounded constraints (e.g.,
double.infinity) in the cross-axis of a flex box (RoworColumn) or within scrollable regions (ListView). This causes render exceptions.
Structural Widgets
Select the appropriate structural Widget based on the required spatial arrangement.
- Use
RowandColumn: ImplementRowfor horizontal linear layouts andColumnfor vertical linear layouts. Control child alignment usingmainAxisAlignmentandcrossAxisAlignment. - Use
ExpandedandFlexible: Wrap children ofRoworColumninExpandedto force them to fill available space, orFlexibleto allow them to size themselves up to the available space. - Use
Container: Wrap Widgets in aContainerwhen you need to apply padding, margins, borders, or background colors. - Use
Stack: ImplementStackwhen Widgets must overlap on the Z-axis. UsePositionedto anchor children to specific edges of theStack. - Use
SizedBox: Enforce strict, tight constraints on a child Widget by wrapping it in aSizedBoxwith explicitwidthandheightvalues.
Adaptive and Responsive Design
Apply conditional logic to handle varying screen sizes and form factors.
- If fitting UI into available space (Responsive): Use
LayoutBuilder,Expanded, andFlexibleto dynamically adjust the size and placement of elements based on the parent's constraints. - If adjusting UI usability for a specific form factor (Adaptive): Use conditional rendering to swap entire layout structures. For example, render a bottom navigation bar on mobile, but a side navigation rail on tablets/desktop.
Workflow: Implementing a Complex Layout
Follow this sequential workflow to architect and implement robust Flutter layouts.
Task Progress
- Phase 1: Visual Deconstruction
- Break down the target UI into a hierarchy of rows, columns, and grids.
- Identify overlapping elements (requiring
Stack). - Identify scrolling regions (requiring
ListVieworSingleChildScrollView).
- Phase 2: Constraint Planning
- Determine which Widgets require tight constraints (fixed size) vs. loose constraints (flexible size).
- Identify potential unbounded constraint risks (e.g., a
ListViewinside aColumn).
- Phase 3: Implementation
- Build the layout from the outside in, starting with the
Scaffoldand primary structural Widgets. - Extract deeply nested layout sections into separate, stateless Widgets to maintain readability.
- Build the layout from the outside in, starting with the
- Phase 4: Validation and Feedback Loop
- Run the application on target devices/simulators.
- Run validator -> review errors -> fix: Open the Flutter Inspector. Enable "Debug Paint" to visualize render boxes.
- Check for yellow/black striped overflow warnings.
- If overflow occurs: Wrap the overflowing Widget in
Expanded(if inside a flex box) or wrap the parent in a scrollable Widget.
Examples
Example: Resolving Unbounded Constraints in Flex Boxes
Anti-pattern: Placing a ListView directly inside a Column causes an unbounded height exception because the Column provides infinite vertical space to the ListView.
// BAD: Throws unbounded height exception
Column(
children: [
Text('Header'),
ListView(
children: [/* items */],
),
],
)
Implementation: Wrap the ListView in an Expanded Widget to bound its height to the remaining space in the Column.
// GOOD: ListView is constrained to remaining space
Column(
children: [
Text('Header'),
Expanded(
child: ListView(
children: [/* items */],
),
),
],
)
Example: Responsive Layout with LayoutBuilder
Implement LayoutBuilder to conditionally render different structural Widgets based on available width.
Widget buildAdaptiveLayout(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
// Conditional logic based on screen width
if (constraints.maxWidth > 600) {
// Tablet/Desktop: Side-by-side layout
return Row(
children: [
SizedBox(width: 250, child: SidebarWidget()),
Expanded(child: MainContentWidget()),
],
);
} else {
// Mobile: Stacked layout with navigation
return Column(
children: [
Expanded(child: MainContentWidget()),
BottomNavigationBarWidget(),
],
);
}
},
);
}
Facts
- Kind
- Skill
- Repo
- flutter/agent-plugins
- Group
- Uncategorized
- Installs
- 10.6k
- Stars
- 3.1K
- 1find-skillsvercel-labs/skillsHelps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.3.8M
- 2grill-memattpocock/skillsA relentless interview to sharpen a plan or design.1.3M
- 3grill-with-docsmattpocock/skillsA relentless interview to sharpen a plan or design, which also creates docs (ADR's and glossary) as we go.1.1M
- 4agent-browservercel-labs/agent-browserBrowser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.1.1M
- 5improve-codebase-architecturemattpocock/skillsScan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.1.1M
- 6tddmattpocock/skillsTest-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.1.1M