skills.vishalvoidskills/vishalvoid
Creative & DesignIntermediate

flutter-building-layouts

Build and fix layouts using the constraint system (Row, Column, Stack)

Developer Setup

Setup & Installation

bash
npx skills add https://github.com/flutter/skills --skill flutter-building-layouts

Overview

What This Skill Does

Build and fix layouts using the constraint system (Row, Column, Stack)

Application

When to use this Skill

Documentation

Show Skills.md file

Architecting Flutter Layouts

Contents

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 x and y coordinates 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 (Row or Column) or within scrollable regions (ListView). This causes render exceptions.

Structural Widgets

Select the appropriate structural Widget based on the required spatial arrangement.

  • Use Row and Column: Implement Row for horizontal linear layouts and Column for vertical linear layouts. Control child alignment using mainAxisAlignment and crossAxisAlignment.
  • Use Expanded and Flexible: Wrap children of Row or Column in Expanded to force them to fill available space, or Flexible to allow them to size themselves up to the available space.
  • Use Container: Wrap Widgets in a Container when you need to apply padding, margins, borders, or background colors.
Lines 1 - 25 of 120

Recommendations

Explore other random skills

All skillsMy patterns