build method
Describes the part of the user interface represented by this component.
The framework calls this method in a number of different situations. For example:
- After calling initState.
- After calling didUpdateComponent.
- After receiving a call to setState.
- After a dependency of this
State
object changes (e.g., anInheritedComponent
referenced by the previous build changes). - After calling deactivate and then reinserting the
State
object into the tree at another location.
This method can potentially be called in every frame and should not have any side effects beyond building a component.
The framework replaces the subtree below this component with the component
returned by this method, either by updating the existing subtree or by
removing the subtree and inflating a new subtree, depending on whether the
component returned by this method can update the root of the existing
subtree, as determined by calling Component.canUpdate
.
Typically implementations return a newly created constellation of components
that are configured with information from this component's constructor, the
given BuildContext
, and the internal state of this State
object.
The given BuildContext
contains information about the location in the
tree at which this component is being built. For example, the context
provides the set of inherited components for this location in the tree. The
BuildContext
argument is always the same as the context
property of
this State
object and will remain the same for the lifetime of this
object. The BuildContext
argument is provided redundantly here so that
this method matches the signature for a ComponentBuilder
.
See also:
StatefulComponent
, which contains the discussion on performance considerations.
Implementation
@override
Iterable<Component> build(BuildContext context) sync* {
if (_matchList?.title case var title?) {
yield Document.head(title: title);
}
yield* component._builder.build(this);
}