Overview
Fern’s layout system provides declarative widgets for arranging UI components. Layouts automatically position children based on alignment, spacing, and flex rules.Layout Widgets
Row - Horizontal Layout
Arrange widgets horizontally from left to right:- Basic Usage
- With Alignment
- With Spacing
Column - Vertical Layout
Stack widgets vertically from top to bottom:Center - Centering Layout
Center a single widget within available space:Center automatically handles window resizing when implementing ResponsiveWidget.Padding - Spacing Around Widgets
Add space around widgets:Expanded - Flex Spacing
Make widgets expand to fill available space with flex factors:Alignment Options
MainAxisAlignment
Controls alignment along the primary direction (horizontal for Row, vertical for Column):CrossAxisAlignment
Controls alignment perpendicular to the main axis:SizedBox - Empty Space
Create empty space of specific dimensions:Complex Layouts
Grid-like Layout with Rows and Columns
Dashboard Layout
Nested Layouts
Layouts can be nested for complex arrangements:Responsive Layouts
Layouts automatically adjust to window size:Best Practices
Row for horizontal toolbars, button groupsColumn for forms, vertical listsCenter for modals, splash screensExpanded for responsive sections// Good
Row(children, false, MainAxisAlignment::SpaceBetween)
// Avoid calculating positions manually
Next Steps
- Learn about Styling to customize appearance
- Explore Responsive Design patterns
- See Creating Widgets for custom components