Layout

A layout system similar to Tailwind CSS, allowing you to create responsive layouts using Flexbox and Grid systems.

Overview

The Layout Utilities in FlutterWind provide a powerful way to create responsive layouts using Flexbox and Grid systems, similar to Tailwind CSS. These utilities allow you to build complex layouts with minimal code.

Flexbox Utilities

Flexbox is a one-dimensional layout method for arranging items in rows or columns. FlutterWind provides comprehensive flexbox utilities to control container and item behavior.

Flex Direction

Control the direction of flex items with these utilities:

ClassUsage
flexDefault flex row layout
flex-rowArrange items horizontally (left to right)
flex-colArrange items vertically (top to bottom)
flex-row-reverseArrange items horizontally (right to left)
flex-col-reverseArrange items vertically (bottom to top)

Flex Wrap

Control whether flex items wrap onto multiple lines:

ClassUsage
flex-wrapAllow items to wrap onto multiple lines
flex-nowrapPrevent items from wrapping
flex-wrap-reverseWrap items in reverse order

Justify Content

Control how items are positioned along the main axis:

ClassUsage
justify-startItems aligned to the start
justify-endItems aligned to the end
justify-centerItems centered along the line
justify-betweenItems evenly distributed with first item at start, last at end
justify-aroundItems evenly distributed with equal space around them
justify-evenlyItems evenly distributed with equal space between them

Align Items

Control how items are positioned along the cross axis:

ClassUsage
items-startItems aligned to the start of the cross axis
items-endItems aligned to the end of the cross axis
items-centerItems centered along the cross axis
items-stretchItems stretched to fill the container along the cross axis
items-baselineItems aligned by their baselines

Align Content

Control how lines are positioned when there's extra space in the cross axis:

ClassUsage
content-startLines packed at the start
content-endLines packed at the end
content-centerLines centered in the container
content-betweenLines evenly distributed with first line at start, last at end
content-aroundLines evenly distributed with equal space around them
content-stretchLines stretched to fill the container

Align Self

Override the alignment for individual flex items:

ClassUsage
self-autoDefault auto alignment
self-startItem aligned to the start
self-endItem aligned to the end
self-centerItem centered
self-stretchItem stretched to fill the container
self-baselineItem aligned by its baseline

Flex Grow / Shrink

Control how flex items grow or shrink:

ClassUsage
flex-growAllow item to grow to fill available space
flex-grow-0Prevent item from growing
flex-shrinkAllow item to shrink if necessary
flex-shrink-0Prevent item from shrinking

Flex Basis

Set the initial main size of a flex item:

ClassUsage
basis-autoDefault size based on content
basis-0Size of 0
basis-1/250% of the container
basis-1/333.333% of the container
basis-2/366.667% of the container
basis-1/425% of the container
basis-3/475% of the container
basis-[200px]Custom size of 200px

Grid System

The grid system allows for two-dimensional layouts with rows and columns. FlutterWind provides utilities to create and control grid layouts.

Grid Template Columns

Define the columns of your grid:

Define the columns of your grid:

ClassUsage
gridEnable grid layout
grid-cols-1One column grid
grid-cols-2Two column grid
grid-cols-3Three column grid
grid-cols-4Four column grid
grid-cols-5Five column grid
grid-cols-6Six column grid
grid-cols-12Twelve column grid
grid-cols-noneNo defined columns

Grid Column Span

Control how many columns an item spans:

// Use the colSpan extension method
Container().colSpan(2)  // Span 2 columns
Container().colSpan(3)  // Span 3 columns
Container().colSpan(4)  // Span 4 columns

Grid Template Rows

Define the rows of your grid:

ClassUsage
grid-rows-1One row grid
grid-rows-2Two row grid
grid-rows-3Three row grid
grid-rows-4Four row grid
grid-rows-5Five row grid
grid-rows-6Six row grid
grid-rows-noneNo defined rows

Grid Gap

Control the gap between grid items:

ClassUsage
gap-0No gap
gap-14px gap
gap-28px gap
gap-416px gap
gap-832px gap
gap-[20px]Custom 20px gap
gap-x-416px horizontal gap
gap-y-416px vertical gap

Grid Auto Flow

Control how auto-placed items are inserted in the grid:

ClassUsage
grid-flow-rowItems fill rows
grid-flow-colItems fill columns
grid-flow-denseDense packing algorithm

Usage in Code

Layout utilities are applied through the FlutterWind styling system:

Flexbox Example

// Create a row with centered items
Container(
  child: [
    Text('Item 1'),
    Text('Item 2'),
    Text('Item 3'),
  ].className('flex justify-center items-center'),
)

// Create a column with items aligned to the start
Container(
  child: [
    Text('Item 1'),
    Text('Item 2'),
    Text('Item 3'),
  ],
).className('flex flex-col items-start')

Grid Example

// Create a 3-column grid with gap
Container(
  child: [
    Container(color: Colors.red, height: 100).colSpan(1),
    Container(color: Colors.blue, height: 100).colSpan(2),
    Container(color: Colors.green, height: 100).colSpan(2),
    Container(color: Colors.yellow, height: 100).colSpan(1),
  ].className('grid grid-cols-6 gap-2')
)

Implementation Details

The layout utilities are implemented in the layout.dart file, which provides two main components:

  1. FlexBox Layout: Implemented using Flutter's Row and Column widgets with various properties to control alignment, justification, and item behavior.
  2. Grid Layout: Implemented using a custom grid system that arranges children in a grid pattern based on the specified number of columns and rows.

The GridItemWrapper class and colSpan extension method allow for controlling how many columns a grid item spans, similar to the col-span-* utility in Tailwind CSS.

Responsive layouts can be created by combining these utilities with FlutterWind's responsive design system, allowing for different layouts at different screen sizes.