Layout in Flutter

Tram Ho

In Flutter, there are a lot of widgets to display on the screen, but in order for them to display at the position and size we want, in this article I will make a cheat sheet about the layout in fluter for your reference:

Layout in Flutter

Row and Column

MainAxisAlignment

For Row/Column use MainAxisAlignment to align content against the main axis is main axis

Row:

Column:

Opposite to start to be end We will get the following:

Row:

Column:

To create space between the widgets in the column we use properties like spaceBetweenspaceEvenlyspaceAround

SpaceBetween: For this property will create equal spacing between the child widgets but the first and last child widget will be close to the outer border:

Row:

Column:

SpaceEvenly: With this property will create equal spacing between child widgets no matter how large the size of the outer widget is.

Row:

Column:

SpaceAround: This property will create a padding around each child widget, depending on the number of widgets and the size of the widget outside it will automatically calculate the space around the outside for each widget.

Row:

Column:

CrossAxisAlignment

Used to specify how the child widgets should be arranged on the cross axis, on the column the vertical axis and the row on the horizontal axis.

Row:

Column:

Row:

Column:

Center: Will put all the child widgets inside to the center

Row:

Column:

MainAxisSize

Size of external widget widget

Row:

Column:

Row:

Column:

Expanded

Expanded is a widget that automatically fills the space of the Row / Column content, in case there are many child widgets, it will automatically align evenly or we can also use the property flex to set the percentage that the content of the child widget will take up.

Container

Container is a widget to contain only 1 widget in it, this widget if there are no child widgets will automatically be the size of the parent widget and if there are child widgets inside, this widget will automatically trim the size. according to the content of the child widget. This is similar to div html side.

  • Does not contain any child widgets:

  • Contains child widgets:

SizedBox

SizedBox is quite similar to Container but it will not be able to set properties like paddingmargincolor

SafeArea

In case we want the widget content not to be covered by the status bar of Android or Notch iPhone, this is a very useful widget.

Reference

Share the news now