|
| 1 | +--- |
| 2 | +slug: /concepts/layouts/flex |
| 3 | +title: Flex |
| 4 | +description: Learn how to add the Flex widget in your FlutterFlow app. |
| 5 | +tags: [Flex, Widget, Concepts] |
| 6 | +sidebar_position: 2 |
| 7 | +keywords: [FlutterFlow, Wrap, Concepts] |
| 8 | +--- |
| 9 | + |
| 10 | +# Flex |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +## Adding Flex Widget |
| 19 | + |
| 20 | +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. |
| 21 | + |
| 22 | +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. |
| 23 | + |
| 24 | +<div style={{ |
| 25 | + position: 'relative', |
| 26 | + paddingBottom: 'calc(56.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding |
| 27 | + height: 0, |
| 28 | + width: '100%'}}> |
| 29 | + <iframe |
| 30 | + src="https://demo.arcade.software/3zWIgGDDec21fNIeCVOU?embed&show_copy_link=true" |
| 31 | + title="" |
| 32 | + style={{ |
| 33 | + position: 'absolute', |
| 34 | + top: 0, |
| 35 | + left: 0, |
| 36 | + width: '100%', |
| 37 | + height: '100%', |
| 38 | + colorScheme: 'light' |
| 39 | + }} |
| 40 | + frameborder="0" |
| 41 | + loading="lazy" |
| 42 | + webkitAllowFullScreen |
| 43 | + mozAllowFullScreen |
| 44 | + allowFullScreen |
| 45 | + allow="clipboard-write"> |
| 46 | + </iframe> |
| 47 | +</div> |
| 48 | +<p></p> |
| 49 | + |
| 50 | +Here's another example of using a Flex widget on a create account page to dynamically align the signup fields based on screen size. |
| 51 | + |
| 52 | +<div style={{ |
| 53 | + position: 'relative', |
| 54 | + paddingBottom: 'calc(56.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding |
| 55 | + height: 0, |
| 56 | + width: '100%'}}> |
| 57 | + <iframe |
| 58 | + src="https://demo.arcade.software/HPk574WhIatWbJBdlxtf?embed&show_copy_link=true" |
| 59 | + title="" |
| 60 | + style={{ |
| 61 | + position: 'absolute', |
| 62 | + top: 0, |
| 63 | + left: 0, |
| 64 | + width: '100%', |
| 65 | + height: '100%', |
| 66 | + colorScheme: 'light' |
| 67 | + }} |
| 68 | + frameborder="0" |
| 69 | + loading="lazy" |
| 70 | + webkitAllowFullScreen |
| 71 | + mozAllowFullScreen |
| 72 | + allowFullScreen |
| 73 | + allow="clipboard-write"> |
| 74 | + </iframe> |
| 75 | +</div> |
| 76 | +<p></p> |
| 77 | + |
| 78 | +:::tip[Best Practices] |
| 79 | + |
| 80 | +- If you only need a simple vertical or horizontal arrangement, consider using [**Row**](../../../resources/ui/widgets/composing-widgets/rows-column-stack.md) or [**Column**](../../../resources/ui/widgets/composing-widgets/rows-column-stack.md). |
| 81 | +- For very large numbers of children, consider using [**ListView**](../../../resources/ui/widgets/composing-widgets/list-grid.md#listview-widget) or [**GridView**](../../../resources/ui/widgets/composing-widgets/list-grid.md#gridview-widget) instead of **Flex**, as they offer better performance for scrolling large lists of items. |
| 82 | +- 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**](wrap-widget.md) widget. |
| 83 | + |
| 84 | +::: |
| 85 | + |
| 86 | +## Customization |
| 87 | + |
| 88 | +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](../../../resources/ui/widgets/composing-widgets/rows-column-stack.md#main-axis), [cross axis alignment](../../../resources/ui/widgets/composing-widgets/rows-column-stack.md#cross-axis), [scrollability](../../../resources/ui/widgets/composing-widgets/rows-column-stack.md#scrollability), and [spacing](../../../resources/ui/widgets/composing-widgets/rows-column-stack.md#spacing) work the same way they do for the Column and Row widgets. |
| 89 | + |
| 90 | + |
0 commit comments