flutter-building-layouts
Builds Flutter layouts using the constraint system and layout widgets. Use when creating or refining the UI structure of a Flutter application.
- License 许可
- MIT
- 最近更新
- 2026-06-13
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- flutter-building-layouts
- description
- Builds Flutter layouts using the constraint system and layout widgets. Use when creating or refining the UI structure of a Flutter application.
03 SKILL.md 正文
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
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.
Phase 4: Validation
- [ ] Run the application on target devices/simulators.
- [ ] 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
// BAD: Throws unbounded height exception
Column(
children: [
Text('Header'),
ListView(
children: [/* items */],
),
],
)
// GOOD: ListView is constrained to remaining space
Column(
children: [
Text('Header'),
Expanded(
child: ListView(
children: [/* items */],
),
),
],
)
Example: Responsive Layout with LayoutBuilder
Widget buildAdaptiveLayout(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth > 600) {
return Row(
children: [
SizedBox(width: 250, child: SidebarWidget()),
Expanded(child: MainContentWidget()),
],
);
} else {
return Column(
children: [
Expanded(child: MainContentWidget()),
BottomNavigationBarWidget(),
],
);
}
},
);
}
04 同仓库更多 Skills
hello-checker
Use this skill when asked to "verify", "check", or "validate" a file's existence and content. It provides a reliable workflow for confirming files meet their spec.
ask-skill
暂无简介
html-review-artifact
Framework-wide guidance for crafting polished human-review artifacts as markdown or HTML
converge-planning
Design a Converge playbook end-to-end. Use when the user says "plan a project", "design a playbook", "decompose into tasks", "scaffold a Converge workflow", "onboard to Converge", or asks how to write TASK.md / playbook.yml. Two entry points: plan a new playbook or update an existing one. Hand off to `/converge-control` after producing the playbook structure.
converge-control
Operate a Converge playbook end-to-end — start runs, monitor progress, narrow failures with `--select`, inspect runtime state, validate definitions, surgically reset subtrees, and stop stuck or orphaned runs. Use this skill whenever the user says "run my playbook", "execute this", "monitor the run", "converge failed", "the run is stuck", "retry failures", "babysit this playbook", "what's the status?", "show me the gantt", or asks how to use `converge run` / `--select` / `inspect` / `doctor` / `clean` / `stop`. Also use it for `HTTP 401` / `Invalid API key` failures on the first task — those are environment-not-playbook problems — and for any post-run cleanup work. Hand off to `converge-planning` if the user wants to design or restructure the playbook itself.
repair-taskts
Fix task.ts definition issues — Seed syntax, missing .build(), empty checks, import errors, TypeScript errors