Collection.custom constructor
const
Collection.custom({
- Key? key,
- required IndexedWidgetBuilder? builder,
- required int? childCount,
Creates a custom Collection using a builder with MultiSliver support.
This constructor is for advanced scenarios where sliver-based rendering is needed for each
child. It requires both builder and childCount, as MultiSliver needs a fixed number of
sliver children. An assertion ensures childCount is provided. This mode generates a list of
slivers using the builder and wraps them in MultiSliver.
Suitable for collections where each item is a sliver widget, such as nested Sections or other slivers.
Example:
Collection.custom(
builder: (context, index) => SliverToBoxAdapter(
child: ListTile(title: Text('Item $index')),
),
childCount: 50,
)
Implementation
const Collection.custom(
{super.key, required this.builder, required this.childCount})
: children = const [],
customBuilder = true,
assert(childCount != null,
'childCount must be provided for custom builders as MultiSlivers are being used to build the list');