Row in Flutter is one of the most commonly used widgets to create UI layouts. It is used to arrange other widgets in a horizontal direction.

A Row widget arranges its children widgets horizontally, from left to right.

In this blog post, we will explore the Row widget in Flutter, how to use it, and its properties.

What is a Row in Flutter?

In Flutter, the Row widget is used to arrange its child widgets in a horizontal row. The children of a Row are laid out in the order they are added, from left to right by default. You can add any number of child widgets to a Row, and they will be placed one after another. The Row widget is a flexible widget that adjusts its width based on the size of its children.

How to use the Row Widget in Flutter?

Using the Row widget in Flutter is simple. You can add any number of child widgets to a Row, and they will be placed horizontally, one after another. Here’s an example of how to use the Row widget in Flutter:

Row(
        children: [
         const Text('First'),
          ElevatedButton(child: const Text("Click me"),onPressed:(){}),
         Container(
           padding: const EdgeInsets.all(20),
           color:Colors.red,
           child:const Text("Text")),
        ],
      ),

Output

row in flutter
Row in Flutter

Properties of the Row Widget

The Row widget has several properties that allow you to customize its behavior and appearance. Let’s take a look at some of the most commonly used properties of the Row widget in Flutter:

Row widgets in Flutter have a property called mainAxisAlignment and crossAxisAlignment, which determines how the children’s widgets should be aligned along the main axis and the cross-axis.

row in flutter
Axis example

1) mainAxisAlignment

For the Row widget, the main axis is horizontal.

There are various options for main axis alignment.

a) MainAxisAlignment.start: It aligns the children at the start of the main axis i.e left of the screen. It is the default alignment of the main axis in Row.

Row(
        mainAxisAlignment:MainAxisAlignment.start,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )

Output
The out for the MainAxisAlignment.start is the same as the image output above.

b) MainAxisAlignment.end: It aligns the children at the end of the main axis i.e right side of the screen.

Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )

Output

row in flutter
Mainaxis alignment.end

c) MainAxisAlignment.center: It centers the children along the main axis.

Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )

Output

row in flutter
MainAxisAlignment.center

d) MainAxisAlignment.spaceEvenly: It distributes the children evenly along the main axis, with equal space between each child and the edges.

 Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
row in flutter
MainAxisAlignment.spaceEvenly

e) MainAxisAlignment.spaceBetween: It distributes the children evenly along the main axis, with equal space between each child but not at the edges.

Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
row in flutter
MainAxisAlignment.spaceBetween

f) MainAxisAlignment.spaceAround: It distributes the children evenly along the main axis, with equal space between each child and half the space at the edges.

Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
MainAxisAlignment.spaceAround

2) crossAxisAlignment

You can also set the crossAxisAlignment property to control how the children should be aligned perpendicular to the main axis (i.e., along the cross-axis). The available options for crossAxisAlignment are similar to those for mainAxisAlignment.

a) CrossAxisAlignment.start: It aligns the children at the start of the cross-axis (top).

Row(
        crossAxisAlignment:CrossAxisAlignment.start,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
CrossAxisAlignment.start

b) CrossAxisAlignment.end: It aligns the children at the end of the cross-axis (bottom).

Row(
        crossAxisAlignment:CrossAxisAlignment.end,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
row in flutter
CrossAxisAlignment.end

c) CrossAxisAlignment.center: It centers the children widgets along the cross-axis.

Row(
        crossAxisAlignment:CrossAxisAlignment.center,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
CrossAxisAlignment.center

d) CrossAxisAlignment.stretch: It stretches the children to fill the cross axis.

Row(
        crossAxisAlignment:CrossAxisAlignment.stretch,
        children: [
          ElevatedButton(child: const Text("Click me"), onPressed: () {}),
          const Text('First'),
          Container(
              padding: const EdgeInsets.all(20),
              color: Colors.red,
              child: const Text("Text")),
        ],
      )
row in flutter
CrossAxisAlignment.stretch

e) CrossAxisAlignment.baseline: It aligns the children along a common baseline.

3) mainAxisSize

The mainAxisSize property of the Row widget allows you to control the size of the Row widget along the main axis. There are two available options for mainAxisSize:

a) MainAxisSize.max: The Row widget will take up as much horizontal space as possible.

b) MainAxisSize.min: The Row widget will take up only as much horizontal space as needed to contain its children widgets.

Conclusion

The Row widget is a powerful tool for laying out child widgets horizontally in a Flutter app. By using the MainAxisAlignment and CrossAxisAlignment properties, you can control how the child widgets are aligned along the horizontal and vertical axes, respectively. With the Row widget, you can create beautiful and effective layouts for your mobile applications in Flutter.

Thanks for reading this article 

Also, follow to get updated on exciting articles and projects.

If I got something wrong? Let me know in the comments. I would love to improve.

Let’s get connected

We can be friends. Find on FacebookLinkedinGithubYouTube

BuyMeACoffee, and Instagram.

Contribute: BuyMeACoffee

ContactContact Us

  1. Lin Holshue Avatar

    You could definitely see your expertise in the paintings you write. The sector hopes for even more passionate writers like you who aren’t afraid to mention how they believe. At all times follow your heart. “Until you walk a mile in another man’s moccasins you can’t imagine the smell.” by Robert Byrne.

  2. wrongful eviction louisiana Avatar

    Good day! I could have sworn I’ve been to this website before but after reading through some of the post I realized it’s new to me. Anyways, I’m definitely glad I found it and I’ll be bookmarking and checking back often!

  3. eviction notices sent to elderly in louisiana Avatar

    Thanks for some other excellent article. Where else may anyone get that kind of info in such a perfect method of writing? I have a presentation next week, and I’m on the look for such information.

  4. lighting Avatar

    Can I just say what a relief to find somebody who actually is aware of what theyre speaking about on the internet. You undoubtedly know how you can convey a problem to mild and make it important. More people must read this and perceive this side of the story. I cant imagine youre not more widespread since you positively have the gift.

  5. slot gacor 4d Avatar

    Great goods from you, man. I’ve understand your stuff previous to and you are just too excellent. I actually like what you have acquired here, certainly like what you are stating and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I cant wait to read far more from you. This is actually a terrific website.

  6. fishing Avatar

    Simply want to say your article is as astonishing. The clearness in your post is just nice and i can assume you’re an expert on this subject. Fine with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the enjoyable work.

  7. zoritoler imol Avatar

    Its excellent as your other blog posts : D, appreciate it for putting up.

  8. tlover tonet Avatar

    Great – I should certainly pronounce, impressed with your website. I had no trouble navigating through all the tabs as well as related information ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your client to communicate. Nice task.

  9. zoritoler imol Avatar

    My brother recommended I might like this blog. He was totally right. This post actually made my day. You cann’t imagine simply how much time I had spent for this info! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Row in Flutter