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

    Visibility

    Three ways to hide part of the screen. They differ in what happens to the hidden part: whether it takes up space and whether its state stays alive (typed text, scroll position, animation).

    Element Space of the hidden part State of the hidden part
    Visibility none (or kept with maintainSize ) lost (or kept with maintainState )
    Offstage none kept, animations stopped
    IndexedStack a box the size of the largest child kept for all, animations of hidden ones stopped

    If the element is simply not needed, an if: condition on the element itself is simpler: a hidden Visibility remains a child, and the parent's spacing still leaves a gap for it.

    Visibility

    Shows or hides its child. By default a hidden child is removed entirely: it takes no space and loses its state.

    Type: single-child

    @open:false
    @note:""
    Column
      TextButton onPressed:{open = !open}
        Text "Comment"
      Visibility visible:$open maintainState:true
        TextField value:$note onChanged:(value){note = value}
    Parameter Type Default Description
    visible bool true Whether to show the child
    maintainState bool false Keep the hidden child alive: typed text and scroll position are preserved
    maintainAnimation bool false Do not stop the hidden child's animations. Requires maintainState
    maintainSize bool false Keep the hidden child's space (empty). Requires maintainAnimation and maintainState
    maintainInteractivity bool false Accept taps on the hidden child. Requires maintainSize
    maintainSemantics bool false Keep the hidden child visible to the screen reader. Requires maintainSize

    The maintain* flags stack in steps, as in Flutter: each next one only makes sense together with the previous ones.

    @ready:false
    Visibility visible:$ready maintainSize:true maintainAnimation:true maintainState:true
      Text "The space under the text is taken while it is hidden"

    Offstage

    Lays out its child but does not draw it and does not let taps through to it. The child's state is alive, but it is muted : animations are stopped, a Video inside is paused.

    Type: single-child

    Offstage offstage:true
      Text "Hidden"
    Parameter Type Default Description
    offstage bool true Whether to hide the child. Note: by default it hides

    IndexedStack

    Shows one child out of several and keeps the rest alive . That is the difference from Visibility : a tab you return to still has its typed text and scroll position. Hidden children are alive but muted — animations are stopped, a Video is paused.

    Type: multi-child

    @tab:0
    Column spacing:12
      Row spacing:8
        TextButton onPressed:{tab = 0}
          Text "First"
        TextButton onPressed:{tab = 1}
          Text "Second"
      IndexedStack index:$tab
        Text "Contents of the first tab"
        Text "Contents of the second tab"
    Parameter Type Default Description
    index int 0 Index of the shown child, from zero. An index outside the list shows nothing (no error)
    alignment alignment topStart How the children sit inside the box
    sizing string loose Size of the children: loose (their own), expand (the whole box), passthrough (the parent's constraints as they are)
    clipBehavior string hardEdge Whether to clip what goes past the box: none , hardEdge , antiAlias , antiAliasWithSaveLayer

    The box size follows the largest child, not the shown one: switching tabs does not move what is below.

    Differences between the app and the site

    • Visibility with a variable in visible toggles live on the site ( display ). With a constant false the hidden part does not get into the page. maintainSize and the other maintain* flags are not read on the site: the hidden part leaves no space.
    • Offstage on the site is decided once, when the page is built : a variable in offstage is taken at its initial value and does not toggle visibility afterwards. To toggle on the site, use Visibility or IndexedStack .
    • IndexedStack on the site: all children lie in one grid cell, the shown one is opaque, the rest are transparent and do not accept taps; switching happens live on the index variable. alignment and sizing are not read (children sit at the start). clipBehavior:none gives overflow: visible . index must be a plain variable ( $tab ): an expression in index does not switch on the site.

    See also

    • Switcher — pick one child by id , without keeping the others
    • Stack — children on top of each other, all visible
    • Opacity — transparency without hiding