Skip to content

<builder>

A tag that wraps its children in a builder function.

This tag is extremely useful when the parent requires a builder function, such as PageView.builder. Use vars, multiChild, and nullable attributes to define the builder function signature. When the builder function executes, the values of named arguments defined in vars are stored as dependencies in the current Dependencies instance. The values of placeholder arguments (_) are simply ignored. The BuildContext is never stored as a dependency, even if explicitly named, because it would cause a memory leak.

Attributes

Name Description Required Default
dependenciesScope Defines the method for passing Dependencies to immediate children. Valid values are new, copy, and inherit. no auto
for The name of the parent's attribute that will be assigned the builder function. yes null
multiChild Whether the builder function should return an array of widgets or a single widget. no false
nullable Whether the builder function can return null. no false
vars A comma separated list of builder function arguments. Values of named arguments are stored as dependencies. Supports up to five arguments. no null

Example

XML
<PageView.builder>
    <builder for="itemBuilder" vars="_,index" nullable="true">
        <Container>
            <Text data="${index}"/>
        </Container>
    </builder>
</PageView.builder>