body: Row(
children: [
Text(
"Flutter Demo Row",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,
fontSize: 22),
),
Text(
"Flutter Demo Row",
style: TextStyle(
backgroundColor: Colors.indigo,
color: Colors.white,
fontSize: 22),
),
Text(
"Flutter Demo Row",
style: TextStyle(
backgroundColor: Colors.purple,
color: Colors.white,
fontSize: 22),
)
],
)
Column
A Column is a widget used to display child widgets vertically. The Column widget does not scroll. If you have a line of widgets and want them to be able to scroll then you can use ListView Widget which we will discuss in coming blogs.
If we wished to display three text widgets within a column we can create a Column widget like below:
body: Column(
children: [
Text(
"Flutter Demo Row",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,
fontSize: 22),
),
Text(
"Flutter Demo Row",
style: TextStyle(
backgroundColor: Colors.indigo,
color: Colors.white,
fontSize: 22),
),
Text(
"Flutter Demo Row",
style: TextStyle(
backgroundColor: Colors.purple,
color: Colors.white,
fontSize: 22),
)
],
)
Properties of Row and Column Widgets:
1. children:
This property takes in List<Widget>, which is a list of widgets to display inside the Row or the Column widget. we have already seen how children's properties work in the upside-mentioned example.
we can give multiple widgets to the children as it gives the List of widgets like Text, Button, images, listview, Images, and many more properties. All these widgets we are learning in a new blog. Now Let's take an example of children with multiple and different widgets.
Example of Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of Column :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
2. mainAxisAlignment and crossAxisAlignment:
We can control how a row widget aligns its children based on our requirements using the property crossAxisAlignment and mainAxisAlignment. The row's cross-axis will run vertically, and the main axis will run horizontally. See the below visual representation to understand it more clearly.
- 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.
This property takes in the MainAxisAlignment enum to decide how the children's widgets should be placed in mainAxisAlignment. For Row it is horizontal and for Column it is vertical.
We can align the row's children widget with the help of the following properties:
start: It will place the children from the starting of the main axis.
end: It will place the children at the end of the main axis.
center: It will place the children in the middle of the main axis.
spaceBetween: It will place the free space between the children evenly.
spaceAround: It will place the free space between the children evenly and half of that space before and after the first and last children widget.
spaceEvenly: It will place the free space between the children evenly and before and after the first and last children's widget.
Example of Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of Column :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
3. mainAxisSize:
This property decides the size of the main-axis by taking in MainAxisSize enum as the object. It Minimizes the amount of free space along the main axis, subject to the incoming layout constraints. It has two constraints Max and Min Let's see the example of both of the how we can implement.
Example of Min Row :-
body: Center(
child : Container(
color: Colors.indigo,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
)
Example of Max Row :-
body: Center(
child : Container(
color: Colors.indigo,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
)
Example of Min Column :-
body: Center(
child : Container(
color: Colors.indigo,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
)
Example of Max Column :-
body: Center(
child : Container(
color: Colors.indigo,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
)
4. textBaseline:
This property is responsible for the alignment of the text in the Row or Column widget on the basis of a baseline.
Example of Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of Column :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
5. Key:
A new widget will only be used to update an existing element if its key is the same as the key of the current widget associated with the element. like, If you need to update some widgets then you can give the key for those widgets if it matches the condition then update. For more detail, we can understand in the blog of Form Widget.
6. 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.
Example of RTL Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
textDirection: TextDirection.rtl,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of LTR Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
textDirection: TextDirection.ltr
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of RTL Column :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
textDirection: TextDirection.rtl
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of LTR Column :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
textDirection: TextDirection.ltr
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white,),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
7. verticalDirection:
This property takes in VerticalDirection enum as the object to determine the order in which the children should be layered. Two types of VerticalDirection are there let's see an example.
Example of VerticalDirection Down Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
verticalDirection: VerticalDirection.down,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of VerticalDirection Down Column :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
verticalDirection: VerticalDirection.down,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of VerticalDirection Up Row :-
body: Container(
height: double.infinity,
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
verticalDirection: VerticalDirection.up,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Example of VerticalDirection Up Column:-
body: Container(
height: double.infinity,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
verticalDirection: VerticalDirection.up,
children: [
Text(
"Flutter Demo ",
style: TextStyle(
backgroundColor: Colors.deepOrange,
color: Colors.white, ),
),
ElevatedButton(
child: Text(
'ElevatedButton',
style: TextStyle(color: Colors.white,),
),
onPressed: () {},
),
OutlinedButton(
child: Text(
'OutlinedButton',
style: TextStyle(color: Colors.blueGrey,),
),
onPressed: () {},
),
],
),
)
Information with easy to grasp content.
ReplyDeleteKeep going.
Best wishes.
Thank You
Delete