Skip to content

Commit 4be08ef

Browse files
committed
fix #5278: enhance Row and ResponsiveRow documentation and improve alignment handling
1 parent 55b4e0e commit 4be08ef

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

packages/flet/lib/src/controls/row.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ class RowControl extends StatelessWidget {
1818
debugPrint("Row build: ${control.id}");
1919

2020
var spacing = control.getDouble("spacing", 10)!;
21-
var mainAlignment = parseMainAxisAlignment(
22-
control.getString("alignment"), MainAxisAlignment.start)!;
23-
var tight = control.getBool("tight", false)!;
2421
var wrap = control.getBool("wrap", false)!;
25-
var intrinsicHeight = control.getBool("intrinsic_height", false)!;
26-
var verticalAlignment = control.getString("vertical_alignment");
2722
var controls = control.buildWidgets("controls");
2823

2924
Widget child = wrap
@@ -35,20 +30,23 @@ class RowControl extends StatelessWidget {
3530
control.getString("alignment"), WrapAlignment.start)!,
3631
runAlignment: parseWrapAlignment(
3732
control.getString("run_alignment"), WrapAlignment.start)!,
38-
crossAxisAlignment: parseWrapCrossAlignment(
39-
verticalAlignment, WrapCrossAlignment.center)!,
33+
crossAxisAlignment: control.getWrapCrossAlignment(
34+
"vertical_alignment", WrapCrossAlignment.center)!,
4035
children: controls,
4136
)
4237
: Row(
4338
spacing: spacing,
44-
mainAxisAlignment: mainAlignment,
45-
mainAxisSize: tight ? MainAxisSize.min : MainAxisSize.max,
46-
crossAxisAlignment: parseCrossAxisAlignment(
47-
verticalAlignment, CrossAxisAlignment.center)!,
39+
mainAxisSize: control.getBool("tight", false)!
40+
? MainAxisSize.min
41+
: MainAxisSize.max,
42+
mainAxisAlignment: control.getMainAxisAlignment(
43+
"alignment", MainAxisAlignment.start)!,
44+
crossAxisAlignment: control.getCrossAxisAlignment(
45+
"vertical_alignment", CrossAxisAlignment.center)!,
4846
children: controls,
4947
);
5048

51-
if (intrinsicHeight) {
49+
if (control.getBool("intrinsic_height", false)!) {
5250
child = IntrinsicHeight(child: child);
5351
}
5452

sdk/python/packages/flet/src/flet/controls/core/responsive_row.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ResponsiveRow(LayoutControl, AdaptiveControl):
2727
Similar to `expand` property, every control has [`col`][flet.Control.]
2828
property which allows specifying how many columns a control should span.
2929
30+
Example:
3031
```python
3132
ft.ResponsiveRow(
3233
controls=[
@@ -40,10 +41,10 @@ class ResponsiveRow(LayoutControl, AdaptiveControl):
4041
},
4142
)
4243
for i in range(1, 6)
43-
],
44+
],
4445
)
4546
```
46-
47+
4748
"""
4849

4950
controls: list[Control] = field(default_factory=list)
@@ -64,8 +65,13 @@ class ResponsiveRow(LayoutControl, AdaptiveControl):
6465

6566
vertical_alignment: CrossAxisAlignment = CrossAxisAlignment.START
6667
"""
67-
Defines how the child [`controls`][(c).] should be placed
68-
vertically.
68+
Defines how the child [`controls`][(c).] should be placed vertically.
69+
70+
Note:
71+
When [`wrap`][(c).] is `True`, this property doesn't support
72+
[`CrossAxisAlignment.STRETCH`][flet.] or
73+
[`CrossAxisAlignment.BASELINE`][flet.]. If either is used,
74+
[`CrossAxisAlignment.START`][flet.] will be applied instead.
6975
"""
7076

7177
spacing: ResponsiveNumber = 10
@@ -80,7 +86,7 @@ class ResponsiveRow(LayoutControl, AdaptiveControl):
8086

8187
run_spacing: ResponsiveNumber = 10
8288
"""
83-
The spacing between runs when row content is wrapped on multiple lines.
89+
The spacing between runs when [`wrap`][(c).] is `True`.
8490
"""
8591

8692
breakpoints: dict[Union[ResponsiveRowBreakpoint, str], Number] = field(

sdk/python/packages/flet/src/flet/controls/core/row.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ class Row(LayoutControl, ScrollableControl, AdaptiveControl):
1818
To cause a child control to expand and fill the available horizontal space, set
1919
its [`expand`][(c).] property.
2020
21+
Example:
2122
```python
22-
ft.Row(
23-
controls=[
24-
ft.Card(
25-
shape=ft.ContinuousRectangleBorder(radius=10),
26-
content=ft.Container(
27-
padding=5,
28-
border_radius=ft.BorderRadius.all(5),
29-
bgcolor=ft.Colors.AMBER_100,
30-
content=ft.Text(f"Control {i}"),
31-
),
32-
)
33-
for i in range(1, 6)
34-
],
35-
),
23+
(
24+
ft.Row(
25+
controls=[
26+
ft.Card(
27+
shape=ft.ContinuousRectangleBorder(radius=10),
28+
content=ft.Container(
29+
padding=5,
30+
border_radius=ft.BorderRadius.all(5),
31+
bgcolor=ft.Colors.AMBER_100,
32+
content=ft.Text(f"Control {i}"),
33+
),
34+
)
35+
for i in range(1, 6)
36+
],
37+
),
38+
)
3639
```
3740
3841
"""
@@ -50,6 +53,12 @@ class Row(LayoutControl, ScrollableControl, AdaptiveControl):
5053
vertical_alignment: CrossAxisAlignment = CrossAxisAlignment.CENTER
5154
"""
5255
Defines how the child [`controls`][(c).] should be placed vertically.
56+
57+
Note:
58+
When [`wrap`][(c).] is `True`, this property doesn't support
59+
[`CrossAxisAlignment.STRETCH`][flet.] or
60+
[`CrossAxisAlignment.BASELINE`][flet.]. If either is used,
61+
[`CrossAxisAlignment.CENTER`][flet.] will be applied instead.
5362
"""
5463

5564
spacing: Number = 10
@@ -64,30 +73,33 @@ class Row(LayoutControl, ScrollableControl, AdaptiveControl):
6473

6574
tight: bool = False
6675
"""
67-
Specifies how much space should be occupied horizontally.
76+
Whether this row should occupy all available horizontal space (`True`),
77+
or only as much as needed by its children [`controls`][(c).] (`False`).
6878
69-
Defaults to `False`, meaning all space is allocated to children.
79+
Note:
80+
Has effect only when [`wrap`][(c).] is `False`.
7081
"""
7182

7283
wrap: bool = False
7384
"""
74-
When set to `True` the Row will put child controls into additional rows (runs) if
75-
they don't fit a single row.
85+
Whether this row should put child [`controls`][(c).] into additional rows (runs) if
86+
they don't fit in a single row.
7687
"""
7788

7889
run_spacing: Number = 10
7990
"""
80-
Spacing between runs when `wrap=True`.
91+
The spacing between runs when [`wrap`][(c).] is `True`.
8192
"""
8293

8394
run_alignment: MainAxisAlignment = MainAxisAlignment.START
8495
"""
85-
How the runs should be placed in the cross-axis when `wrap=True`.
96+
How the runs should be placed in the cross-axis when [`wrap`][(c).] is `True`.
8697
"""
8798

8899
intrinsic_height: bool = False
89100
"""
90-
If `True`, the Row will be as tall as the tallest child control.
101+
Whether this row should be as tall as the tallest child control in
102+
[`controls`][(c).].
91103
"""
92104

93105
def init(self):

0 commit comments

Comments
 (0)