Protected against bots by Yandex SmartCaptcha. Data processing policy
Flex
A linear layout whose axis is a parameter.
Row
and
Column
are a
Flex
with a fixed axis;
Flex
is for when the axis is decided by an expression: "a row on a wide screen, a column on a narrow one" — one element with one condition instead of the whole section written twice.
Type:
multi-child
Flex direction:horizontal spacing:12
Text "Left"
Text "Right"
The other parameters are the same as for
Row
and
Column
, including the short synonyms, so a section moved to
Flex
is written with the same words.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
direction
|
string | vertical |
Axis:
horizontal
or
vertical
. Without the parameter — a column
|
mainAxisAlignment
|
string | start |
Alignment along the main axis:
start
,
end
,
center
,
spaceBetween
,
spaceAround
,
spaceEvenly
|
alignment
|
string | start |
Synonym of
mainAxisAlignment
(read when that one is absent)
|
mainAxisSize
|
string | max |
Size along the main axis:
min
— fit the children,
max
— all available space
|
size
|
string | max |
Synonym of
mainAxisSize
|
crossAxisAlignment
|
string | center |
Alignment along the cross axis:
start
,
end
,
center
,
stretch
,
baseline
|
crossAlignment
|
string | center |
Synonym of
crossAxisAlignment
|
spacing
|
length | 0 |
Gap between children: a number (px) or a length in viewport units (
"2vw"
). Percent is not supported
|
textDirection
|
string | — |
ltr
or
rtl
: which way the horizontal axis runs
|
textBaseline
|
string | — |
alphabetic
or
ideographic
. With
crossAxisAlignment:baseline
and no value,
alphabetic
is used
|
Examples
Axis by the box width
The width comes from
LayoutBuilder
; on the site, a condition on it becomes a
@container
rule and is correct from the very first frame.
LayoutBuilder maxWidth:@w
Flex direction:{w > 480 ? "horizontal" : "vertical"} spacing:16 crossAxisAlignment:start
ColoredBox color:0xFFE0E7FF
Padding
#padding all 16
Text "Section text"
ColoredBox color:0xFFC7D2FE
Padding
#padding all 16
Text "Illustration"
Axis by the screen size class
For page-level bands, take the axis from
$theme.sizeClass
— on the site this is a
@media
rule (see
responsive layout
).
Flex direction:{$theme.sizeClass == "compact" ? "vertical" : "horizontal"} spacing:24
Text "Heading"
Text "Description"
Baseline alignment
Flex direction:horizontal crossAxisAlignment:baseline textBaseline:alphabetic spacing:8
Text "128"
#style fontSize:40 fontWeight:bold
Text "steps"
Differences between the app and the site
-
On the site
Flexisdisplay: flexwithflex-direction: roworcolumn. -
An axis computed from the
LayoutBuilderwidth goes into@container, one from$theme.sizeClass— into@media;spacingis carried over the same way. -
An axis from ordinary state (an
@varchanged by a button) does not switch on the site : it is taken from the initial value when the page is built and does not change afterwards. In the app it changes. To make the axis change on the site, compute it from the width or from the size class.
See also
- Row , Column — the same layout with a fixed axis
- Expanded , Flexible — how to share space between children
- Screen and available space — where to get the width for choosing the axis
- Responsive site layout — rules for the site