FItemGroup.builder constructor
FItemGroup.builder({
- required NullableIndexedWidgetBuilder itemBuilder,
- int? count,
- FItemGroupStyle style()?,
- ScrollController? scrollController,
- double? cacheExtent,
- double maxHeight = double.infinity,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- ScrollPhysics physics = const ClampingScrollPhysics(),
- bool? enabled,
- FItemDivider divider = FItemDivider.none,
- String? semanticsLabel,
- Key? key,
Creates a FItemGroup that lazily builds its children.
The itemBuilder is called for each item that should be built. The current level's FInheritedItemData is not
visible to itemBuilder.
- It may return null to signify the end of the group.
- It may be called more than once for the same index.
- It will be called only for indices <=
countifcountis given.
The count is the number of items to build. If null, itemBuilder will be called until it returns null.
Notes
May result in an infinite loop or run out of memory if:
- Placed in a parent widget that does not constrain its size, i.e. Column.
countis null anditemBuilderalways provides a zero-size widget, i.e. SizedBox(). If possible, provide items with non-zero size, return null from builder, or setcountto non-null.
Implementation
FItemGroup.builder({
required NullableIndexedWidgetBuilder itemBuilder,
int? count,
this.style,
this.scrollController,
this.cacheExtent,
this.maxHeight = double.infinity,
this.dragStartBehavior = DragStartBehavior.start,
this.physics = const ClampingScrollPhysics(),
this.enabled,
this.divider = FItemDivider.none,
this.semanticsLabel,
super.key,
}) : assert(0 < maxHeight, 'maxHeight ($maxHeight) must be > 0'),
assert(count == null || 0 <= count, 'count ($count) must be >= 0'),
_builder = ((style, enabled) => SliverList.builder(
itemCount: count,
itemBuilder: (context, index) {
if (itemBuilder(context, index) case final item?) {
return FInheritedItemData.merge(
style: style.itemStyle,
spacing: style.spacing,
enabled: enabled,
dividerColor: style.dividerColor,
dividerWidth: style.dividerWidth,
divider: divider,
index: index,
last: (count != null && index == count - 1) || itemBuilder(context, index + 1) == null,
child: item,
);
}
return null;
},
));