Flutter - Row and Column Widgets
Last Updated :
29 Jun, 2022
Row and Column are the two most important and powerful widgets in Flutter. These widgets let you align children horizontally and vertically as per the requirement. As we know that when we design any UI(User Interface) in a flutter, we need to arrange its content in the Row and Column manner so these Row and Column widgets are required when designing UI.
Constructor Of Column Class:
Column(
{Key key,
MainAxisAlignment mainAxisAlignment: MainAxisAlignment.start,
MainAxisSize mainAxisSize: MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
TextDirection textDirection,
VerticalDirection verticalDirection: VerticalDirection.down,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[]}
)
Constructor Of Row Class:
Row(
{Key key,
MainAxisAlignment mainAxisAlignment: MainAxisAlignment.start,
MainAxisSize mainAxisSize: MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
TextDirection textDirection,
VerticalDirection verticalDirection: VerticalDirection.down,
TextBaseline textBaseline: TextBaseline.alphabetic,
List<Widget> children: const <Widget>[]}
)
Properties of Row and Column Widgets:
- children: This property takes in List<Widget>, that is a list of widgets to display inside the Row or the Column widget.
- clipBehaviour: This property holds Clip class as the object to decide whether the content on the Row or Column should be clipped or not.
- crossAxisAlignment: The crossAxisAlignment takes in CrossAxisAlignment enum as the object to how the children's widgets should be places in crossAxisAlignment. For Row it is vertical and for Column it is horizontal.
- direction: This property holds as the Axis enum object to decide the direction used in the main axis. For Row and Column, it is fixed.
- mainAxisAlignment: This property takes in MainAxisAlignment enum as the object to decide how the children widgets should be place in mainAxisAlignment. For Row it is horizontal and for Column it is vertical.
- mainAxisSize: This property decides the size of main-axis by taking in MainAxisSize enum as the object.
- runtimeType: This property tells the run-time type of the Row or Column widget.
- textBaseline: This property is responsible for the alignment of the text in the Row or Column widget with respect to a baseline.
- textDirection: This property controls the text direction of the Row or Column widget, which can either be from left-to-right (by default) or right-to-left.
- verticalDirection: This property takes in VerticalDirection enum as the object to determine the order in which the children should be layered.
Row:
It creates a horizontal array of children.
Alignment Properties: We can align content as per our choice by using mainAxisAlignment and crossAxisAlignment. Row's mainAxis is horizontal and cross Axis to Row's main Axis is vertical. We can align children horizontally using MainAxisAlignment and vertically using CrossAxisAlignment in that row.
Apart from these mainAxisAlignment and crossAxisAlignment, we also have some other properties like mainAxisSize,textDirection,verticalDirection etc. but we will focus on these two(mainAxisAlignment and crossAxisAlignment) in this article as these are mostly used and others in some other article.
Row
We can align the content by using the following properties:
- start: Place the children from the starting of the row.
- end: Place the children at the end of the row.
- center: Place the children at the center of the row.
- spaceBetween: Place the space evenly between the children.
- spaceAround: Place the space evenly between the children and also half of that space before and after the first and last child.
- spaceEvenly: Place the space evenly between the children and also before and after the first and last child.
We will see the difference with the help of examples. Let's suppose we want to align content such that there is space around the children in a row :
File: main.dart
Dart
import 'package:flutter/material.dart';
//function to trigger build
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'GeeksForGeeks',
theme: ThemeData(
primarySwatch: Colors.green,
),// ThemeData
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
);// MaterialApp
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("GeeksForGeeks"),
),// AppBar
// App body consists of single Row
// Row consists of three children widgets
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: Colors.green),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Geeks",
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: Colors.green),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"For",
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: Colors.green),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Geeks",
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
)
],
),
);
}
}
Output:

Column:
It creates a vertical array of children.
Alignment Properties:
In this also we have mainAxisAlignment and crossAxisAlignment. In column, children are aligned from top to bottom. Main Axis is vertical and the Cross Axis is horizontal. MainAxisAlignment aligns its children vertically and CrossAxisAlignment aligns horizontally in that Column.
Column
We can align the content by using the same properties as discussed above in Row (start, end,spaceBetween,spaceAround,spaceEvenly).
We will see the difference with the help of examples. Let's suppose we want to align content so that we have space around the children . Assign mainAxisAlignment as spaceAround as shown below:
Example
Dart
import 'package:flutter/material.dart';
//function to trigger build
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'GeeksForGeeks',
theme: ThemeData(
primarySwatch: Colors.green,
), // ThemeData
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
); // MaterialApp
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("GeeksForGeeks"),
), // AppBar
// App body consists of single Column
// Column consists of three children widgets
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: Colors.green),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"GeeksForGeeks",
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: Colors.green),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"GeeksForGeeks",
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: Colors.green),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"GeeksForGeeks",
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
)
],
), // Column
);
}
}
Output:

Some more examples are :
mainAxisAlignment.spaceEvenly
mainAxisAlignment.spaceEvenly
mainAxisAlignment.center
mainAxisAlignment.center
mainAxisAlignment.spaceBetween
mainAxisAlignment.spaceBetween
We can also align content using combination of mainAxisAlignment and crossAxisAlignment for both Row and Column. Lets take an example of Row, set mainAxisAlignment as MainAxisAlignment.spaceAround and crossAxisAlignment as CrossAxisAlignment.stretch. By doing this(crossAxisAlignment.stretch), the height of the row will be equal to the height of the body because we have only one row.
Output:

Drawbacks:
- The row has no horizontal scrolling so when a large number of children are inserted in a single row that is not able to fit in the row then it will give us an Overflow message (for ex: Right overflowed by 560px).
- The column has no vertical scrolling so when a large number of children are inserted in a single Column whose total children size is more than the total height of the screen then it will give us an Overflow message (for ex: Bottom overflowed by 684px).
Similar Reads
Dart Tutorial Dart is an open-source general-purpose programming language developed by Google. It supports application development on both the client and server side. However, it is widely used for the development of Android apps, iOS apps, IoT(Internet of Things), and web applications using the Flutter Framework
7 min read
What is Widgets in Flutter? Flutter is Google's UI toolkit for crafting beautiful, natively compiled iOS and Android apps from a single code base. To build any application we start with widgets - The building block of Flutter applications. Widgets describe what their view should look like given their current configuration and
5 min read
Dart - Data Types Like other languages (C, C++, Java), whenever a variable is created, each variable has an associated data type. In Dart language, there are the types of values that can be represented and manipulated in a programming language. In this article, we will learn about Dart Programming Language Data Types
8 min read
Dart SDK Installation To do a lot of interesting programming stuff using the Dart programming language, we have to install the Dart SDK. Dart SDK is a pre-compiled version so we have to download and extract it only. In this article, we will learn how to perform Dart SDK Download.Table of ContentInstall Dart SDK in Window
4 min read
Dart - Variables A variable name is the name assigned to the memory location where the user stores the data and that data can be fetched when required with the help of the variable by calling its variable name. Various types of variables are used to store the data. The kind which will be used to store data depends u
5 min read
Dart - Standard Input Output In Dart programming language, you can take standard input from the user through the console via the use of the .readLineSync() function. To take input from the console you need to import a library, named dart:io from the libraries of Dart.Stdin ClassThis class allows the user to read data from stand
3 min read
Flutter - AppBar Widget AppBar is usually the topmost component of the app (or sometimes the bottom-most), it contains the toolbar and some other common action buttons. As all the components in a Flutter application are a widget or a combination of widgets. So AppBar is also a built-in class or widget in Flutter which give
7 min read
Scaffold class in Flutter with Examples The Scaffold is a class in flutter that provides many widgets or we can say APIs. The Scaffold will expand or occupy the whole available space in device screen .The class Hierarchy is as follows:Object â³ Diagnosticable â³ Diagnosticable Tree â³ Widget â³ StateFul Widget â³ ScaffoldThe constructor of the
8 min read
Introduction to Dart Programming Language Dart is an open-source programming language originally developed by Google. It is designed for both server-side and client-side development. The Dart SDK includes its compiler, the Dart VM, as well as a utility called dart2js, which converts Dart scripts into JavaScript. This makes it possible to ru
4 min read
Operators in Dart The operators are special symbols used to perform certain operations on operands. Dart has numerous built-in operators that can be utilized for various functions; for example, '+' is used to add two operands. Operators are designed to execute operations on one or two operands. Precedence Table of Op
11 min read