Protected against bots by Yandex SmartCaptcha. Data processing policy
AspectRatio
Makes its child keep the given width-to-height ratio. The element takes the maximum available width (or height, if the width is unbounded) and picks the other side from the ratio.
Type:
single-child
AspectRatio aspectRatio:1.78
ColoredBox color:#4f46e5
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
aspectRatio
|
double | 1.0 |
Width ÷ height:
1.78
≈ 16:9,
1.0
— a square,
0.75
— a 3:4 portrait
|
Examples
A 16:9 cover above a column
Column spacing:8
AspectRatio aspectRatio:1.78
Image src:"https://example.com/cover.jpg" fit:cover
Text "Title"
A square tile
SizedBox width:120
AspectRatio aspectRatio:1.0
ColoredBox color:#059669
A rounded poster card
AspectRatio aspectRatio:0.67
ClipRRect
#borderRadius circular 12
Image src:"https://example.com/poster.jpg" fit:cover
Differences between the app and the site
- In the app the element picks the largest size with this ratio that fits the parent's constraints. On the site it takes the available height and computes the width, capping it at the parent's width.
- If the parent fixes both the width and the height, the ratio cannot be kept — the parent wins.
Best practices
-
Give
AspectRatioa bounded width (a column,SizedBox width, a grid cell): the height then follows on its own, with no hard-coded numbers. -
For a grid of identical tiles,
childAspectRatioon GridView works too.
See also
- SizedBox — fixed sizes
- GridView — a grid with one ratio for all cells
- ConstrainedBox — minimum and maximum sizes