Understanding Row & Column in Flutter
Understanding Row & Column in Flutter
COLUMN:
We need to play with CrossAxisAligment & MainAxisAlignment. In the Column
widget, MainAxisAligment will be in the vertical direction & CrossAxisAligment
in the horizontal direction.
Container(
color: Colors.grey[300],
width: double.infinity,
height: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 50,
width: 50,
color: Colors.red,
),
Container(
height: 50,
width: 50,
color: Colors.green,
),
Container(
height: 50,
width: 50,
color: Colors.blue,
),
],
),
),
changed MainAxisAligment.
around.
Center(
child: Container(
height: 100,
width: 100,
child: TextButton(
onPressed: () {},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.android),
Text("Android"),
],
),
),
),
),
Contact Card
Center(
child: Container(
height: 200,
width: 200,
color: Colors.blueGrey[200],
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
CircleAvatar(
backgroundImage: NetworkImage(
"https://softzone.com/logo.png"),
radius: 28,
),
Text("SOFTZONE"),
Text("Learn flutter easily"),
ElevatedButton(
onPressed: () {},
child: Text("Start"),
)
],
),
),
),
Blog Post
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 200,
width: double.infinity,
child: Image.network(
"https://i.pinimg.com/originals/87/b6/e3/87b6e3ebf4d64dc72392e50a9f74bf84.
jpg",
fit: BoxFit.cover,
),
),
Container(
child: Text(
"Heavy Rain is predicted during this summer",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(height: 8),
Text("Posted 5 mins ago"),
SizedBox(height: 8),
Container(
child: Text(
"Lorem Ipsum is simply dummy text of the printing and
typesetting industry. Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of type
and scrambled it to make a type specimen book. It has survived not only
five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. "),
)
],
),
),
),
Container(
color: Colors.grey[300],
width: double.infinity,
height: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 50,
width: 50,
color: Colors.red,
),
Container(
height: 50,
width: 50,
color: Colors.green,
),
Container(
height: 50,
width: 50,
color: Colors.blue,
),
],
),
),
changed MainAxisAligment.
around.
Center(
child: Container(
width: 120,
child: ElevatedButton(
onPressed: () {},
child: Row(
children: [
Icon(Icons.android),
Text("Press Me"),
],
),
),
),
),
Center(
child: Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
OutlinedButton(
onPressed: () {},
child: Icon(Icons.add),
),
Text("10"),
OutlinedButton(
onPressed: () {},
child: Icon(Icons.remove),
),
],
),
),
),
Container(
padding: EdgeInsets.all(16.0),
child: Container(
color: Colors.grey[400],
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
width: 80,
height: 80,
child: Image.network(
"https://i.pinimg.com/originals/87/b6/e3/87b6e3ebf4d64dc72392e50a9f74bf84.
jpg",
fit: BoxFit.cover,
),
),
Container(
child: Text(
"Umberla For Sale",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
Text("5 USD")
],
),
),
),