Flutter Row & Column
Row lays out its children horizontally, Column lays them out vertically. Together they build the majority of Flutter layouts. Both are flex widgets, so if you know CSS flexbox, many ideas will feel familiar.
Main axis and cross axis
Every flex widget has two axes:
| Widget | Main axis | Cross axis |
|---|---|---|
Row |
horizontal → | vertical ↓ |
Column |
vertical ↓ | horizontal → |
mainAxisAlignment positions children along the main axis; crossAxisAlignment positions them across it.
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: Scaffold(body: Center(child: Boxes()))));
class Box extends StatelessWidget {
const Box(this.color, this.size, {super.key});
final Color color;
final double size;
@override
Widget build(BuildContext context) =>
Container(width: size, height: size, color: color);
}
class Boxes extends StatelessWidget {
const Boxes({super.key});
@override
Widget build(BuildContext context) {
return Container(
color: Colors.grey.shade200,
height: 120,
child: const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Box(Colors.red, 40),
Box(Colors.green, 60),
Box(Colors.blue, 80),
],
),
);
}
}Try replacing spaceBetween with the other values:
MainAxisAlignment |
Effect |
|---|---|
start (default) |
Packed at the start |
end |
Packed at the end |
center |
Packed in the middle |
spaceBetween |
Free space only between children |
spaceAround |
Half-size space at both ends |
spaceEvenly |
Equal space everywhere |
CrossAxisAlignment offers start, end, center (default), stretch (fill the cross axis) and baseline (align text baselines).
A Column of content
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: WeatherPage()));
class WeatherPage extends StatelessWidget {
const WeatherPage({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.wb_sunny, size: 72, color: Colors.orange),
SizedBox(height: 8),
Text('24°C', style: TextStyle(fontSize: 48, fontWeight: FontWeight.w300)),
Text('Sunny · Da Nang'),
],
),
),
);
}
}SizedBox(height: 8) is the standard way to put a fixed gap between children. Since Flutter 3.27 you can also write Column(spacing: 8, children: [...]).
mainAxisSize
By default a Row takes all the horizontal space it is given and a Column all the vertical space. mainAxisSize: MainAxisSize.min makes it shrink to fit its children — useful inside buttons, chips or centred groups.
Nesting rows and columns
Real layouts nest flex widgets. A contact row: an avatar, a column with two texts, and an icon at the end.
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: Scaffold(body: SafeArea(child: ContactRow()))));
class ContactRow extends StatelessWidget {
const ContactRow({super.key});
@override
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.all(16),
child: Row(
children: [
CircleAvatar(radius: 24, child: Text('MK')),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Mai Kobayashi', style: TextStyle(fontWeight: FontWeight.bold)),
Text('See you at the station at 9!', overflow: TextOverflow.ellipsis),
],
),
),
Icon(Icons.phone, color: Colors.green),
],
),
);
}
}Expanded makes the middle column take all remaining width, pushing the phone icon to the right edge — you'll learn more about it in the next lessons.
The overflow error
If children are wider than a Row (or taller than a Column), Flutter draws yellow-and-black stripes and prints an error in debug mode:
A RenderFlex overflowed by 42 pixels on the right.
Fixes: wrap a child in Expanded or Flexible so it can shrink, let text wrap or ellipsize, or make the content scrollable with SingleChildScrollView or ListView.
Tip: Enable "Show Guidelines" from Flutter DevTools' Layout Explorer to see how rows and columns distribute space.
Test yourself
In a Column, what does mainAxisAlignment control?
- Horizontal position of children
- Vertical position of children
- The colour of children
- Spacing inside each child
Which value puts equal space before, between and after all children?
- spaceBetween
- spaceAround
- spaceEvenly
- center
How do you make a Row only as wide as its children?
- mainAxisSize: MainAxisSize.min
- crossAxisAlignment: stretch
- Wrap it in Expanded
- mainAxisAlignment: start