LayoutBuilder class final

Builds its child with the constraints it is laid out within, so that what it shows depends on the room it gets: one layout for a wide terminal and another for a narrow one, a pane that collapses.

builder runs in the layout of a frame, not in its build: at the first layout, when the constraints differ from those of the last build, when the widget is replaced, and when an inherited widget the builder depends on changes; at no other layout. What it builds is laid out in the same frame, and the elements below it marked dirty meanwhile are rebuilt with it; those elsewhere wait for the next build scope. While it has a build to do, what is dirty below it waits for that build, as in Flutter: built before it, a row would read the widget above it from before the change that made it dirty. A build that throws is reported as any build is (BuildOwner.onBuildError), and what the owner returns shown in place of the child.

It is as big as its child. Its intrinsic sizes are those of the child it built last, none before its first layout: the builder does not run for them, and a parent laid out by sizes that the next build changed is laid out again on the next frame.

Two panes side by side in a terminal 80 columns wide or more, one above the other in a narrower one:

LayoutBuilder(
  builder: (context, constraints) => constraints.maxWidth >= 80
      ? Row(children: const [Text('list'), Text('details')])
      : Column(children: const [Text('list'), Text('details')]),
)

See also:

  • Builder, which builds with its context in the build, not the layout.
Inheritance

Constructors

LayoutBuilder({required LayoutWidgetBuilder builder, Key? key})
Builds its child with builder at its layout.
const

Properties

builder → LayoutWidgetBuilder
Builds the child for the constraints.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Tells this widget apart from its siblings; see Key.
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → RenderObjectElement
Inflates this widget into a new element for the tree.
override
createRenderObject(BuildContext context) → RenderObject
Creates the render object, configured from this widget.
override
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Adds what describes this widget in its element's description (Element.describe) to properties, those not worth showing (a default) left out; an override calls this first. A render object widget adds only what its render object does not show. Only Element.describe calls it: a frame never does.
inherited
didUnmountRenderObject(covariant RenderObject renderObject) → void
Called when the element of renderObject was unmounted: release what the render object holds.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
updateRenderObject(BuildContext context, covariant RenderObject renderObject) → void
Configures renderObject from this widget: called when it replaced the widget that created or last configured the render object, and when the element is rebuilt.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited