LayoutBuilder class

Builds its child from the constraints it actually receives, so layout can adapt to the available space — a sidebar that collapses below a width, a list that switches to a grid when wide, etc.

The builder runs during layout rather than build. It runs again when the incoming constraints change, when the parent rebuilds this widget, or when something the builder reads changes, such as a scope like MediaQuery.of(context) or an animation's value; otherwise the child it built last time is kept, so the builder doesn't run on every frame. An exception in the builder is handled like one thrown by a build method: the error widget takes the child's place.

An axis can be unbounded: constraints.maxCols or maxRows is null for an inflexible child of a Row or Column, for example. A builder that sizes from that axis needs a bound, so wrap this widget in Expanded or SizedBox. With assertions enabled, a child that comes out zero-sized on an unbounded axis while non-empty on the other throws a StateError that says so.

Inheritance
Available extensions

Constructors

LayoutBuilder({Key? key, required LayoutWidgetBuilder builder})
const

Properties

builder → LayoutWidgetBuilder
Creates the child for the constraints received during the current layout.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

animate({Duration? duration, Curve? curve, Object? trigger, bool repeat = false}) → Animate

Available on Widget, provided by the AnimateExtension extension

Starts an Animate chain over this widget. duration / curve apply to the whole chain. With no trigger it plays on mount; with a non-null trigger it rests on mount and replays whenever the token changes.
createElement() → RenderObjectElement
Creates the Element that will mount this widget into the tree.
override
createRenderObject(BuildContext context) → RenderObject
Creates the render object backing this widget. Called once when the element first mounts.
override
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 RenderLayoutBuilder renderObject) → void
Applies any changes from a new widget instance to the existing render object. Default is a no-op; subclasses override when the widget carries layout/paint configuration.
override

Operators

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