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

    Screen and available space

    Elements through which markup learns how much space it has and what screen is in front of it — and elements that adjust this information for a subtree. These are three different questions, and each has its own element:

    The rules of responsive site layout (when a size class, when LayoutBuilder , what becomes @media and what becomes @container ) are on the page Responsive site layout .

    Values are delivered into variables declared with @ on the value side : maxWidth:@w creates a variable w that this element's subtree reads.

    LayoutBuilder

    Gives its subtree the constraints the parent gave this box: the smallest and largest width and height.

    Type: single-child

    LayoutBuilder maxWidth:@w
      Row spacing:8
        Icon home
        Text "Home" if:{w > 480}
    Parameter Type Default Description
    minWidth @ output — Receives the smallest width the parent allows
    maxWidth @ output — Receives the largest width, or null if the width is unbounded
    minHeight @ output — Receives the smallest height
    maxHeight @ output — Receives the largest height, or null if the height is unbounded

    What arrives are constraints , not a size. A bound can be infinite — for example, the width inside a horizontal scroll view; then null arrives. Check in this order: first "is there a bound" ( w == null ), then "is it wide" — null > 480 is false too.

    LayoutBuilder maxWidth:@w
      ColoredBox color:0xFFE0E7FF
        Padding
          #padding all 16
          Column spacing:8 crossAxisAlignment:start
            Text $"Box width: ${w}"
            Text "Plenty of room — the hint is visible" if:{w > 480}

    On the site LayoutBuilder becomes a CSS container: a condition or a length based on its width becomes @container rules, correct from the first frame; text and mixed conditions are updated by a script after loading. The page is built at a width of 3120 px, and that is the number everything driven by the script sees until the script runs.

    OrientationBuilder

    Gives its subtree the orientation of the box the element received: portrait (taller than wide) or landscape . This is the shape of the space, not the rotation of the device: in a narrow panel on a landscape tablet the answer is portrait .

    Type: single-child

    OrientationBuilder orientation:@o
      Column
        Text "Turn your phone sideways" if:{o == "portrait"}
    Parameter Type Default Description
    orientation @ output — Receives portrait or landscape

    On the site the value does not arrive : only the child is drawn, the variable stays empty, and a condition on it ( if:{o == "portrait"} ) is false at build time — such a branch drops out of the page. For the site, decide the same thing by the LayoutBuilder width.

    ViewportData

    Gives its subtree information about the screen , not the box: window size, device type, keyboard, safe insets, text scale. Needed where LayoutBuilder has no answer: hide the bottom navigation while the keyboard is open; decide "phone or tablet" in one place instead of with thresholds in every file.

    Type: single-child

    ViewportData formFactor:@ff keyboard:@kb
      Column
        Expanded
          Text "Screen"
        Text "Bottom navigation" if:{ff == "phone" && kb == 0}
    Parameter Type Default Description
    width @ output — Receives the window width in logical pixels
    height @ output — Receives the window height
    orientation @ output — Receives portrait or landscape — by the window, not the box
    formFactor @ output — Receives phone (the window's short side is under 600), tablet (under 900) or desktop
    touch @ output — Receives true if the main input is a finger (iOS, Android), otherwise false
    keyboard @ output — Receives how many pixels at the bottom the on-screen keyboard covers (0 — closed)
    safeTop @ output — Receives the device's top safe inset (cutout, status bar)
    safeBottom @ output — Receives the bottom safe inset (the home indicator)
    safeLeft @ output — Receives the left safe inset
    safeRight @ output — Receives the right safe inset
    textScale @ output — Receives the text size multiplier from the reader's settings

    formFactor is about the device: a narrow panel on a tablet is still tablet here. The question "will the caption fit" is for LayoutBuilder . touch and formFactor are different questions: a tablet with a keyboard is still a touch device.

    On the site the values do not arrive : only the child is drawn, all variables are empty, conditions on them are false at build time. For the site, use $theme.sizeClass and LayoutBuilder .

    MediaQuery

    Overrides part of the screen information for its subtree: text scale, bold text, screen insets. Everything not specified stays as it was.

    Type: single-child

    MediaQuery textScaleFactor:1
      Text "This text is not enlarged by the reader's settings"
    Parameter Type Default Description
    textScaleFactor double — Text size multiplier for the subtree
    boldText bool — Treat the reader as having turned on bold text
    #padding EdgeInsets — Screen insets for the subtree — read by SafeArea and ViewportData ( safeTop …)
    MediaQuery boldText:true
      #padding only top:50
      SafeArea
        Text "Under an inset of 50"

    On the site MediaQuery draws only its child; the parameters are not read.

    SafeArea

    Moves its child away from the system parts of the screen: the camera cutout, the status bar, the home indicator, rounded corners.

    Type: single-child

    SafeArea bottom:false
      Text "Below the status bar"
    Parameter Type Default Description
    top bool true Respect the top inset
    bottom bool true Respect the bottom inset
    left bool true Respect the left inset
    right bool true Respect the right inset
    #minimum EdgeInsets 0 The smallest inset on each side — even where the device has none
    maintainBottomViewPadding bool false Keep the bottom inset when the keyboard covers it, so the content does not jump
    SafeArea
      #minimum all 16
      Text "At least 16 on every side"

    On the site the insets come from the browser's env(safe-area-inset-*) , with #minimum as the lower bound; a side that is turned off gets only #minimum . maintainBottomViewPadding is not read.

    Differences between the app and the site

    Element On the site
    LayoutBuilder A CSS container: conditions and lengths based on width become @container , the rest is a script after loading
    OrientationBuilder Only the child, orientation does not arrive
    ViewportData Only the child, no value arrives
    MediaQuery Only the child, the parameters are not read
    SafeArea padding from env(safe-area-inset-*) and #minimum

    See also