Skip to main content

Flex

The Flex widget can be used as an alternative to Row and Column. It allows you to dynamically set the layout axis (horizontal or vertical) based on specific conditions or logic. This is especially useful for creative responsive layouts - where child elements should be horizontal when the screen is wide, and vertical when the screen is narrow.

flex.png

Adding Flex Widget

To use the Flex widget, add it from the Layout Elements section of the Widget Palette, then add child widgets inside it. From the properties panel, set a condition for the Is Horizontal property. When this condition evaluates to True, the items will be laid out horizontally.

Consider an ecommerce app where recent orders are displayed vertically on mobile devices and switch to a horizontal layout on larger screens to make better use of the available space.

Here's another example of using a Flex widget on a create account page to dynamically align the signup fields based on screen size.

Best Practices
  • If you only need a simple vertical or horizontal arrangement, consider using Row or Column.
  • For very large numbers of children, consider using ListView or GridView instead of Flex, as they offer better performance for scrolling large lists of items.
  • When the content exceeds the screen limit, you can enable scrolling to make the content accessible. However, if you want to avoid scrolling altogether and still fit all the content on the screen, consider using a Wrap widget.

Customization

When Is Horizontal property is disabled, the Flex widget behaves like a Column, and when enabled, it acts as a Row. Settings like main axis alignment, cross axis alignment, scrollability, and spacing work the same way they do for the Column and Row widgets.