Row
Row is designed to arrange child widgets horizontally, where the intrinsic sizes of child widgets dictate the layout's appearance.
Best Practices
- Use Row to lay out the children horizontally from left to right. Enable scrollable if the children might exceed the available space.
- Avoid using child widgets with no width constraint or sized itself to the parent (e.g. form inputs such as TextInput) inside the Row. FlexRow may be a better choice in this case.
- Avoid using nested scrollable Row for better UX.
Key Concepts
- mainAxisSize: By default the width of a
Row
is determined by its parent's width constraint (if available), otherwise it will be the combined width of its children. You may force the Row to do the later (size itself to the children's combined width) withmainAxisSize=min
. - mainAxis: This property controls the horizontal alignment of the children within the Row. This property is useful only when the mainAxisSize is set to max (default) as there are available spaces to align the children.
- crossAxis: This property controls the vertical alignment of the children within the Row.
- scrollable: Enable horizontal scrolling when the child widgets grow wider than the available space.
Caveats
- Row height: Note that setting a height for a Row acts more like a maximum height constraint. The Row determines its actual height based on the tallest child, aligning the other children along the vertical cross-axis according to this height. This means if this actual height is less than the specified height, the
crossAxis
only affects the alignment of the children within the determined (lesser) height. If you wish to stretch all the children to the same specified height, addcrossAxis: stretch
in addition to the fixed height.
Test in Kitchen Sink (opens in a new tab)
Properties
Property | Type | Description |
---|---|---|
item-template | object | See properties |
children | array | List of widgets |
styles | object | See properties |
item-template
Property | Type | Description |
---|---|---|
data | string | Bind to an array of data from an API response or a variable |
name | string | Set the name to reference as you iterate through the array of data |
template | The widget to render for each item |
styles
Property | Type | Description |
---|---|---|
mainAxis | string | Control our children's layout horizontally.start center end spaceBetween spaceAround spaceEvenly |
fontSize | integer | Sets the size of the text. |
fontFamily | string | Set the font family applicable for all widgets inside this container, see the list of all available font families here (opens in a new tab). |
gap | integer | The gap between the children in the main direction |
crossAxis | string | Control the vertical alignment of the children.start center end stretch baseline |
mainAxisSize | string | If 'max', stretch the Row to fill its parent's width. Otherwise (min) the Row's width will be its children's combined. |
scrollable | boolean | Set to true so content can scroll horizontally as needed |
autoFit | boolean | Explicitly make the row's height as tall as the largest child, but only if the row's parent does not already assign us a height. This attribute is useful for sizing children who don't have a width (e.g vertical Divider) |
borderRadius | string or integer | The border radius of the widget.This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0. |
borderColor | Color | Sets the border color, starting with '0xFF' for full opacity. transparent black blue white red grey teal amber pink purple yellow green brown cyan indigo lime orange |
borderWidth | integer | Thickness of the border. Minimum value should be 0. |
shadowColor | Color | Sets the box shadow color starting with '0xFF' for full opacity. transparent black blue white red grey teal amber pink purple yellow green brown cyan indigo lime orange |
shadowOffset | array | The values in array define the horizontal and vertical offset of the shadow. Example: if the shadowOffset is set to [2, 4], the shadow will be offset by 2 pixels horizontally and 4 pixels vertically from its original position. |
shadowRadius | string or integer | The border radius of the widget.This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0. |
shadowStyle | string | The blur style to apply on the shadow normal , solid , outer , inner |
stackPositionTop | integer | The distance of the child's top edge from the top of the stack. This is applicable only for Stack's children. |
stackPositionBottom | integer | The distance that the child's bottom edge from the bottom of the stack. This is applicable only for Stack's children. |
stackPositionLeft | integer | The distance that the child's left edge from the left of the stack. This is applicable only for Stack's children. |
stackPositionRight | integer | The distance that the child's right edge from the right of the stack. This is applicable only for Stack's children. |
captureWebPointer | boolean | Applicable for Web only. When overlaying widgets on top of certain HTML container (e.g. Maps), the mouse click is captured by the HTML container, causing issue interacting with the widget. Use this to capture and maintain the mouse pointer on your widget. |
margin | string or integer | Margin with CSS-style notation |
padding | string or integer | Padding with CSS-style value |
width | integer | The width property determines the horizontal size of an element, allowing control over its width dimension within the layout. |
height | integer | The height property determines the vertical size of an element, allowing control over its height dimension within the layout. |
backgroundImage | BackgroundImage | Background image of the box. |
backgroundGradient | Gradient | Background gradient of the box |
backgroundColor | Color | Background color of the box. which can be represented in different formats. It can be specified as a number, a predefined color name, or a hexadecimal value starting with '0x'. transparent black blue white red grey teal amber pink purple yellow green brown cyan indigo lime orange |
expanded | boolean | If the parent is a Row or Column, this flag will stretch this widget in the appropriate direction. (e.g. stretch horizontally for parent of type Row) |
visibilityTransitionDuration | number | Specify the duration in seconds when a widget animates between visible and not visible state. Note that setting this value will cause the widget to still occupy the UI space even when it is not visible. |
elevation | integer | The z-coordinate at which to place this material relative to its parent. A non-zero value will show a shadow, with its size relative to the elevation value. Minimum value: 0, Maximum value: 24 |
elevationShadowColor | integer or string | The shadow color for the elevation, which can be represented in different formats. It can be specified as a number, a predefined color name, or a hexadecimal value starting with '0x'. transparent black blue white red grey teal amber pink purple yellow green brown cyan indigo lime orange |
elevationBorderRadius | string or integer | The border radius of the widget.This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0. |
alignment | string | The alignment of the widget relative to its parent. topLeft , topCenter , topRight , centerLeft , center , centerRight , bottomLeft , bottomCenter , bottomRight |
visible | boolean | Toggle a widget visibility on/off. Note that an invisible widget will not occupy UI space, unless the visibilityTransitionDuration is specified. |
enableSplashFeedback | boolean | Toggles splash effect feedback for the widget when true . |
splashColor | string | Defines the color of the splash effect when enableSplashFeedback is true. |
splashDuration | integer | This is the duration it takes to fill the widget surface with the splashColor.The duration in ms when tap and release on the widget. |
splashFadeDuration | integer | The duration it takes to fade out once tapped. Since a typical tap starts and ends immdiately, this splashFadeDuration executes almost at the same time as the splashDuration, so ideally it should be equal or longer than splashDuration to see the entire effect. |
unconfirmedSplashDuration | integer | This happens when the user tap and hold (not yet released). It is called unconfirmed since the tap will be cancelled if the user moves out of the tap area and release. Usually this should be longer (around 1 secs) to signify that the user has not confirmed the tap. |