Skip to content

In Flutter, Rows, Columns, and Stacks are fundamental layout widgets that help you structure the UI by organizing other widgets in different visual arrangements. Here’s how each one works:

  • Row: A Row arranges its child widgets in a horizontal line. This is useful when you want to place elements side by side across the screen.

  • Column: A Column organizes its child widgets vertically, stacking them from top to bottom. This is ideal for placing elements that need to appear in a vertical sequence, such as a list of messages in a chat app or entries in a form.

  • Stack: A Stack layers its child widgets on top of each other, allowing for overlapping elements. In a Stack, widgets can be positioned absolutely relative to the edges of the Stack, giving you control over the exact location of each element.

Each of these widgets serves different purposes and choosing between them depends on how you need to arrange your UI components:

row-col-stack.png

Common Property: Alignment

Main Axis

The main axis is the primary direction in which child widgets are laid out in a Row or Column.

Row: The main axis runs horizontally. Child widgets are arranged from left to right.

FlutterFlow Studio allows you to set Row’s Main Axis property to the following types:

row-main-axis.png

Row’s Main Axis property has the following types: Start, End, Center, SpaceEvenly, SpaceAround, SpaceBetween

Column: The main axis runs vertically. Child widgets are laid out from top to bottom.

FlutterFlow Studio allows you to set Column’s Main Axis property to the following types:

column-main-axis.png

Column’s Main Axis property has the following types: Start, End, Center, SpaceEvenly, SpaceAround, SpaceBetween

Manipulating the main axis allows you to control how widgets are spaced and how they should expand or align in relation to each other along this primary direction.

Cross Axis

The cross axis is perpendicular to the main axis and controls the alignment and spacing of widgets across this secondary direction. It has the following types: Start, Center, End.

Row: The cross axis runs vertically. It determines how child widgets are aligned from top to bottom within the row.

row-cross.png

Cross Axis types for Row. Main Axis of Row is set to Center.

Column: The cross axis runs horizontally. It controls how child widgets align from left to right within the column.

column-cross.png

Cross Axis types for Column. Main Axis of Column is set to Center

Stack Alignment

For Stacks, the concept of main and cross axes is less applicable because widgets are aligned relative to the entire area of the Stack. In FlutterFlow Studio you can control the Stack children’s alignment using the Stack property called Default Child Alignment which positions the children using X and Y coordinates.

stack-align.png

Understanding these axes and their properties is essential for effectively designing layouts that behave as expected on different screen sizes and orientations, ensuring a robust and flexible UI.

Expansion & Flex (for Row & Column)

When widgets are placed inside a Row or Column in a layout, they gain access to an additional property called Expansion & Flex. This property controls how a widget behaves in terms of taking up available space within its parent Row or Column.

Expanded

The Expansion properties are as follows:

  • Default: Make the widget NOT fill space along the main axis (horizontal for Row, vertical for Column), therefore taking the minimum space required by its contents.

  • Flexible: Allow the widget to take up to the available space along the main axis (horizontal for Row, vertical for Column). You can think of this as giving it a “Max Width” equal to the amount of available space. The widget can take up less space if it is smaller, but otherwise will be constrained to the available width.

  • Expanded: Make the widget fill the space along the main axis (horizontal for Row, vertical for Column).

Let’s understand Flexible concept with another example:

Flex

Additionally, you can utilize Flex factors to determine the flexibility of a widget within its parent container. A Flex factor is an integer assigned to a child widget, indicating its proportional size compared to other children in the same parent. The space a child occupies is determined by its Flex factor in relation to the total Flex factors of all siblings in the layout.

When you assign a flex factor, the widget can expand to fill any available space in the parent container. For instance, in a Row or Column, if one widget has a flex factor of 1 and another has a flex factor of 2, the second widget will take up twice as much space as the first.

Find a video tutorial about Expanded & Flexible:

Scrollability

Scrollability for Row or Column widgets in FlutterFlow Studio determines whether the content within these layouts can extend beyond the visible boundaries of the screen or container, enabling horizontal or vertical scrolling:

  • Allow Scrolling: When enabled, this allows the content to exceed the device or parent container’s screen limits, making the overflow content accessible through scrolling.

  • Do Not Allow Scrolling: If disabled, the content that exceeds the boundaries of the screen or its parent container will not be accessible through scrolling. This setting forces the content to fit within the available visible space, hiding overflow content or potentially causing layout issues.

Spacing

  • Items Spacing: This field sets the space between each child widget within the Row or Column. You can specify a static numerical value that determines the pixel spacing between adjacent children or set it from a variable.
  • Apply to Start & End: When toggled on, this applies the specified item spacing to the beginning and the end of the Row or Column. This effectively adds padding at the start and end of the layout in addition to between the items.

  • Start Spacing and End Spacing: These properties allow for additional specific spacing at the start and end of the Row or Column, respectively. This is useful for fine-tuning the layout to ensure content is visually balanced within the container or to provide clear margins.

Last updated on