build method
Builds the Collection widget based on the provided configuration.
This method determines the appropriate rendering strategy by examining the configuration:
- If a builder is provided and customBuilder is true, it generates a fixed number of slivers using List.generate and wraps them in MultiSliver for sliver contexts.
- If a builder is provided but customBuilder is false, it delegates to SListView.builder for standard, non-sliver list rendering.
- If no builder is used (static children), it inspects the children to check if any is a
Section, Collection, or a sliver via
Widget.isSliver. If sliver-compatible, it renders with MultiSliver; otherwise, it uses SListView for a scrollable list of box widgets.
This adaptive approach ensures compatibility with both sliver and non-sliver layouts, optimizing performance and preventing layout errors in scrollable parents.
Implementation
@override
Widget build(BuildContext context) {
if (builder != null) {
if (customBuilder) {
return MultiSliver(
children: List.generate(childCount!, (i) => builder!(context, i)),
);
}
return SListView.builder(builder: builder);
}
if (children.any((element) =>
element is Section ||
element is Collection ||
element.isSliver(context))) {
return MultiSliver(children: children);
} else {
return SListView(
children: children,
);
}
}