layoutBuilder property

HeroHereSwitcherLayoutBuilder layoutBuilder
final

Lays out the switcher's child and its sky, the layer its flights fly in. Defaults to defaultLayoutBuilder, which puts the sky over the child. skyUnderLayoutBuilder puts it under the child.

Lay the sky out after the child, as both do: after the child in a Stack, or positioned in it, since a stack lays out its positioned children last. Then on each frame a flight finds its heroes where that frame's layout puts them. A sky laid out before the child, such as one before it in a stack that doesn't position it, places its shuttles by the layout of the frame before, so on a window resize they lag a frame behind their heroes.

Shuttles fly where their heroes are on the screen, wherever the sky is. The sky takes the smallest size its constraints allow, so it doesn't size the switcher. To clip the flights to the switcher, give the sky the switcher's size:

HeroHereSwitcher(
  layoutBuilder: (child, sky) => Stack(
    children: [child, Positioned.fill(child: ClipRect(child: sky))],
  ),
  child: child,
)

Implementation

final HeroHereSwitcherLayoutBuilder layoutBuilder;