FTileGroup.builder constructor

FTileGroup.builder({
  1. required NullableIndexedWidgetBuilder tileBuilder,
  2. int? count,
  3. FTileGroupStyle? style,
  4. ScrollController? scrollController,
  5. double? cacheExtent,
  6. double maxHeight = double.infinity,
  7. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  8. ScrollPhysics physics = const ClampingScrollPhysics(),
  9. bool? enabled,
  10. FTileDivider divider = FTileDivider.indented,
  11. String? semanticsLabel,
  12. Widget? label,
  13. Widget? description,
  14. Widget? error,
  15. Key? key,
})

Creates a FTileGroup that lazily builds its children.

The tileBuilder is called for each tile that should be built. FTileData is not visible to tileBuilder.

  • 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 <= count if count is given.

The count is the number of tiles to build. If null, tileBuilder 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.
  • count is null and tileBuilder always provides a zero-size widget, i.e. SizedBox(). If possible, provide tiles with non-zero size, return null from builder, or set count to non-null.

Implementation

FTileGroup.builder({
  required NullableIndexedWidgetBuilder tileBuilder,
  int? count,
  this.style,
  this.scrollController,
  this.cacheExtent,
  this.maxHeight = double.infinity,
  this.dragStartBehavior = DragStartBehavior.start,
  this.physics = const ClampingScrollPhysics(),
  this.enabled,
  this.divider = FTileDivider.indented,
  this.semanticsLabel,
  this.label,
  this.description,
  this.error,
  super.key,
}) : assert(0 < maxHeight, 'maxHeight must be positive.'),
     assert(count == null || 0 <= count, 'count must be non-negative.'),
     delegate = ((style, {required enabled}) => SliverChildBuilderDelegate((context, index) {
       final tile = tileBuilder(context, index);
       if (tile == null) {
         return null;
       }

       return FTileData(
         style: style,
         divider: divider,
         states: {if (!enabled) WidgetState.disabled},
         index: index,
         last: (count != null && index == count - 1) || tileBuilder(context, index + 1) == null,
         pressable: true,
         child: tile,
       );
     }, childCount: count));