Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    Size and constraints

    Wrappers that change not the look but the size of their child: fit it into the available space, set it as a fraction of the parent, remove or impose constraints, align it by the baseline. For ordinary sizes look at SizedBox and ConstrainedBox first — the elements on this page are for when those are not enough.

    Baseline

    Places the child so that its text baseline is baseline away from the top of this box.

    Type: single-child

    Baseline baseline:40 baselineType:alphabetic
      Text "Caption"
    Parameter Type Default Description
    baseline double 0 Distance from the top of the box to the child's baseline
    baselineType string alphabetic Which baseline: alphabetic (Latin, Cyrillic) or ideographic (CJK)

    On the site Baseline draws only the child: the baseline offset is not carried over. To align captions of different sizes on the site too, use Row crossAxisAlignment:baseline .

    FittedBox

    Scales the child so that it fits into the given space — for example, a large number in a narrow tile.

    Type: single-child

    SizedBox width:120 height:48
      FittedBox fit:contain
        Text "1 284 500"
          #style fontSize:40 fontWeight:bold
    Parameter Type Default Description
    fit string contain How to fit: contain (whole), cover (fill, cropping the excess), fill (stretch), fitWidth , fitHeight , none , scaleDown (only shrink)
    alignment alignment center The point relative to which the child is placed and scaled
    clipBehavior string none Whether to clip what goes outside the box: none , hardEdge , antiAlias , antiAliasWithSaveLayer

    On the site the box takes the given space, and a small page script computes the scale from the child's size; the part beyond the box edge is always clipped on the site.

    FractionallySizedBox

    Sets the child's size as a fraction of the space the parent gave.

    Type: single-child

    SizedBox width:300 height:120
      ColoredBox color:0xFFE0E7FF
        FractionallySizedBox widthFactor:0.5 heightFactor:0.5 alignment:center
          ColoredBox color:0xFF4F46E5
    Parameter Type Default Description
    widthFactor double — Fraction of the parent's width ( 0.5 — half). Without the parameter the child's width is unchanged
    heightFactor double — Fraction of the parent's height
    alignment alignment center Where the child sits within the available space

    The fraction is taken from the parent's constraint, so in a scroll view along the same axis (where the space is infinite) there is nothing to compute it from. A simple width fraction can also be written as a length — Container width:"50%" .

    IntrinsicHeight

    Makes the child as tall as its "natural" height. The typical case is a row where all columns must be as tall as the tallest one.

    Type: single-child

    IntrinsicHeight
      Row crossAxisAlignment:stretch spacing:8
        ColoredBox color:0xFFE0E7FF
          Padding
            #padding all 12
            Text "Short"
        ColoredBox color:0xFFC7D2FE
          Padding
            #padding all 12
            Text "Long text\non two lines"

    No parameters. Layout with IntrinsicHeight is more expensive than usual (the tree is measured twice) — do not put it on long lists. On the site it is a block with max-content height, and the row inside gets height stretching — the columns come out equal, as in the app.

    IntrinsicWidth

    Makes the child as wide as its "natural" width. The typical case is a column of buttons as wide as the widest one.

    Type: single-child

    @answer:""
    IntrinsicWidth
      Column crossAxisAlignment:stretch spacing:8
        FilledButton onPressed:{answer = "yes"}
          Text "Yes"
        FilledButton onPressed:{answer = "later"}
          Text "Remind me later"
    Parameter Type Default Description
    stepWidth double — Round the width up to a multiple of this number
    stepHeight double — Round the height up to a multiple of this number

    On the site it is a block with max-content width; stepWidth and stepHeight are not read.

    LimitedBox

    Constrains the child only when the parent has not constrained it — for example, inside a scroll view along the same axis. In an ordinary layout it does nothing.

    Type: single-child

    ListView
      LimitedBox maxHeight:120
        ColoredBox color:0xFF059669
    Parameter Type Default Description
    maxWidth double infinity Maximum width if the parent did not constrain the width
    maxHeight double infinity Maximum height if the parent did not constrain the height

    On the site LimitedBox draws only the child: maxWidth and maxHeight are not carried over. If the constraint is always needed, use ConstrainedBox or SizedBox .

    OverflowBox

    Gives the child its own constraints instead of the parent's — the child can become larger than the parent and extend past its edge. The box itself stays the size of the parent.

    Type: single-child

    SizedBox width:100 height:100
      OverflowBox maxWidth:160 maxHeight:160 alignment:center
        ColoredBox color:0x667C3AED
    Parameter Type Default Description
    minWidth double — Minimum width of the child; without it — the parent's
    maxWidth double — Maximum width of the child; without it — the parent's
    minHeight double — Minimum height of the child
    maxHeight double — Maximum height of the child
    alignment alignment center How the child sits relative to the box

    On the site the child gets the maxWidth width and the maxHeight height (if they are set) and is not clipped; minWidth and minHeight are not read.

    UnconstrainedBox

    Removes the parent's constraints from the child: the child is laid out at its own size. If it is larger than the parent, in the app this is an overflow.

    Type: single-child

    UnconstrainedBox alignment:centerLeft
      SizedBox width:200 height:48
        ColoredBox color:0xFF4F46E5
    Parameter Type Default Description
    alignment alignment center Where the child sits inside the box
    constrainedAxis string — The axis along which the constraints are still kept: horizontal or vertical
    clipBehavior string none Whether to clip what goes outside the box

    On the site it is a flex container aligned by alignment ; constrainedAxis and clipBehavior are not read.

    Placeholder

    A rectangle with a border and two diagonals — a stand-in for a part of the screen that is not ready yet. If the element has a child, it is drawn inside the border.

    Type: single-child

    SizedBox width:200 height:100
      Placeholder color:0xFFDC2626 strokeWidth:3
    Parameter Type Default Description
    color color 0xFF455A64 Color of the border and diagonals
    strokeWidth double 2 Line thickness
    fallbackWidth double 400 Width if the parent did not constrain the width
    fallbackHeight double 400 Height if the parent did not constrain the height

    On the site the border and diagonals are drawn with styles; the box fills the parent's space, and fallbackWidth / fallbackHeight become the minimum size (in the app they are the size only under an unconstrained parent). So on the site a Placeholder without an explicit fallbackHeight is never shorter than 400 px. The child of a Placeholder is not drawn on the site.

    Differences between the app and the site

    Summary:

    Element On the site
    Baseline Only the child; the offset is not carried over
    FittedBox The page script computes the scale; overflow beyond the edge is always clipped
    FractionallySizedBox A grid with fractions of the parent — as in the app
    IntrinsicHeight / IntrinsicWidth max-content along its axis; the stepWidth / stepHeight steps are not read
    LimitedBox Only the child; the constraints are not carried over
    OverflowBox The child gets maxWidth / maxHeight and is not clipped; the minimums are not read
    UnconstrainedBox Alignment works, constrainedAxis and clipBehavior do not
    Placeholder A border with diagonals; fallback* is the minimum size; the child is not drawn

    See also