BuildableComponent class abstract Components Core
A Component that does not require mutable state.
A BuildableComponent is a component whose output is determined entirely by its configuration and does not hold mutable state. It describes part of the UI purely from its configuration and builds a tree of other components that represent its contents.
The build method is called when the BuildableComponentInstance is created, producing a fixed set of child Components for rendering. Any change in appearance or layout requires creating a new BuildableComponent with updated configuration.
For dynamic or interactive components that depend on internal state, use a StatefulComponent instead.
Example:
class Menu extends BuildableComponent {
final List<String> items;
const Menu(this.items);
@override
List<Component> build() {
return items.map((label) => TextComponent(label)).toList();
}
}
Performance considerations
Because a BuildableComponent has no internal state, it can be reused and rebuilt efficiently. To maximize performance:
- Use
const
constructors where possible. - Keep the build method minimal, avoiding unnecessary nested components.
See also:
- BuildableComponentInstance for the runtime representation.
- StatefulComponent for stateful, mutable UI.
Constructors
- BuildableComponent.new()
-
Creates a stateless, buildable component.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- padding → EdgeInsets
-
The padding inside the component’s layout bounds.
finalinherited
- position → Position?
-
The position of the component within its parent or layout.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
) → List< Component> - Builds and returns the list of child Components for this component.
-
createInstance(
) → BuildableComponentInstance -
Creates a ComponentInstance that can be rendered.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited