Collection.builder constructor
const
Collection.builder({
- Key? key,
- required IndexedWidgetBuilder? builder,
- int? childCount,
Creates a Collection using a builder for dynamic child generation.
This constructor enables the builder pattern for efficient rendering of potentially large lists.
It requires an IndexedWidgetBuilder to generate widgets on demand and optionally specifies the
childCount for the total number of items. Custom builder mode is disabled, using
SListView.builder internally.
The builder function is called for each index to produce a child widget. If childCount is
provided, it limits the number of built items; otherwise, it builds indefinitely until a null
is returned from the builder.
Example:
Collection.builder(
builder: (context, index) => ListTile(title: Text('Item $index')),
childCount: 100,
)
Implementation
const Collection.builder({super.key, required this.builder, this.childCount})
: children = const [],
customBuilder = false;