Using Rows and Columns in Flutter

 ๐Ÿ“ Row vs. Column Overview

Widget Layout Direction Example Use

Row Horizontal Buttons next to each other

Column Vertical Stack elements like title, subtitle, and button


๐Ÿ”น Basic Syntax

๐Ÿ”ธ Row Example

dart

Copy

Edit

Row(

  mainAxisAlignment: MainAxisAlignment.spaceBetween,

  children: <Widget>[

    Icon(Icons.menu),

    Text('Title'),

    Icon(Icons.search),

  ],

)

๐Ÿ”ธ Column Example

dart

Copy

Edit

Column(

  mainAxisAlignment: MainAxisAlignment.center,

  crossAxisAlignment: CrossAxisAlignment.start,

  children: <Widget>[

    Text('Hello'),

    Text('World'),

    ElevatedButton(

      onPressed: () {},

      child: Text('Click me'),

    ),

  ],

)

๐ŸŽฏ Key Properties

๐Ÿ”น mainAxisAlignment

Controls alignment along the main axis:


start, center, end, spaceBetween, spaceAround, spaceEvenly


๐Ÿ”น crossAxisAlignment

Controls alignment perpendicular to the main axis:


start, center, end, stretch, baseline


๐Ÿ“Œ In a Row, the main axis is horizontal, and the cross axis is vertical. In a Column, it's the reverse.


⚠️ Common Gotchas

❗ Row or Column Takes Infinite Space

Wrap them in Expanded, Flexible, or give them size constraints using Container, SizedBox, etc.


dart

Copy

Edit

Row(

  children: [

    Expanded(child: Text("This text will expand to fill space")),

    Icon(Icons.more_vert),

  ],

)

๐Ÿงฑ Nesting Rows and Columns

You can nest them to build complex layouts:


dart

Copy

Edit

Column(

  children: [

    Row(

      children: [

        Icon(Icons.star),

        Text('Rating: 4.5'),

      ],

    ),

    Text('Review goes here...'),

  ],

)

๐Ÿงฐ Bonus Tips

Use Spacer() inside a Row or Column to push elements apart.


Use SizedBox(height: 10) for spacing in Columns, or width for Rows.


Wrap text-heavy widgets in Expanded or Flexible to avoid overflow.

Learn Flutter Training in Hyderabad

Read More

Creating Responsive Layouts in Flutter

๐Ÿงฉ UI & Layout in Flutter

Working with Text and Images in Flutter

How to Use the Flutter Debug Console

Visit Our IHUB Talent Training Institute in Hyderabad

Get Directions


Comments

Popular posts from this blog

Handling Frames and Iframes Using Playwright

Tosca for API Testing: A Step-by-Step Tutorial

Working with Tosca Parameters (Buffer, Dynamic Expressions)