LayoutBuilder class

A widget that provides its parent's constraints to a builder callback.

Use LayoutBuilder to build widget trees that depend on the available space. The builder receives the BoxConstraints from the nearest MediaQuery ancestor (falling back to unconstrained if none exists).

This is useful for responsive terminal UIs that adapt their layout based on the terminal size.

LayoutBuilder(
  builder: (context, constraints) {
    final theme = ThemeScope.of(context);
    if (constraints.maxWidth > 80) {
      return Row(children: [sidebar, content]);
    }
    return Column(children: [sidebar, content]);
  },
)
Inheritance

Constructors

LayoutBuilder({required Widget builder(BuildContext context, BoxConstraints constraints), Key? key})

Properties

builder Widget Function(BuildContext context, BoxConstraints constraints)
Called to build the widget tree with the available constraints.
final
children List<Widget>
Child widgets that receive forwarded messages.
no setterinherited
debugRenderObjectPassthrough bool
Whether this widget is intentionally transparent to render-object layouts.
no setterinherited
focusable bool
Whether this widget can receive keyboard focus.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier for this widget.
no setterinherited
key Key?
Key for preserving widget identity.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
theme Theme
Access the current theme.
no setterinherited

Methods

build(BuildContext context) Widget
Describes the part of the UI represented by this widget.
override
buildCachedView<T>(T builder(), Object? cacheKey) → T
Returns a cached view if the cache key matches.
inherited
handleInit() Cmd?
Override this instead of init for widget-specific initialization.
inherited
handleIntercept(Msg msg) → (Widget, Cmd?)
Override this to handle messages before they reach children.
inherited
handleUpdate(Msg msg) → (Widget, Cmd?)
Override this to handle messages specific to this widget.
inherited
init() Cmd?
Called once when the widget is first mounted.
inherited
invalidateCachedView() → void
Clears any cached view for this widget.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
update(Msg msg) → (Model, Cmd?)
Handles messages by forwarding to children then calling handleUpdate.
inherited
view() Object
Renders the widget to a string or View.
inherited

Operators

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