FSelectTileGroup<T>.builder constructor

FSelectTileGroup<T>.builder({
  1. required FSelectTileGroupController<T> selectController,
  2. required FSelectTile<T>? tileBuilder(
    1. BuildContext context,
    2. int index
    ),
  3. int? count,
  4. ScrollController? scrollController,
  5. FTileGroupStyle? style,
  6. double? cacheExtent,
  7. double maxHeight = double.infinity,
  8. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  9. ScrollPhysics physics = const ClampingScrollPhysics(),
  10. FItemDivider divider = FItemDivider.indented,
  11. Widget? label,
  12. Widget? description,
  13. String? semanticsLabel,
  14. ValueChanged<Set<T>>? onChange,
  15. ValueChanged<(T, bool)>? onSelect,
  16. Widget errorBuilder(
    1. BuildContext context,
    2. String message
    ) = FFormFieldProperties.defaultErrorBuilder,
  17. FormFieldSetter<Set<T>>? onSaved,
  18. FormFieldValidator<Set<T>>? validator,
  19. String? forceErrorText,
  20. bool enabled = true,
  21. AutovalidateMode? autovalidateMode,
  22. Key? key,
})

Creates a FSelectTileGroup that lazily builds its children.

The tileBuilder is called for each tile that should be built. The current level's FInheritedItemData 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

FSelectTileGroup.builder({
  required this.selectController,
  required FSelectTile<T>? Function(BuildContext context, int index) tileBuilder,
  int? count,
  this.scrollController,
  this.style,
  this.cacheExtent,
  this.maxHeight = double.infinity,
  this.dragStartBehavior = DragStartBehavior.start,
  this.physics = const ClampingScrollPhysics(),
  this.divider = FItemDivider.indented,
  this.label,
  this.description,
  this.semanticsLabel,
  this.onChange,
  this.onSelect,
  Widget Function(BuildContext context, String message) errorBuilder = FFormFieldProperties.defaultErrorBuilder,
  super.onSaved,
  super.validator,
  super.forceErrorText,
  super.enabled = true,
  super.autovalidateMode,
  super.key,
}) : super(
       initialValue: selectController.value,
       errorBuilder: errorBuilder,
       builder: (field) {
         final state = field as _State;

         return FTileGroup.builder(
           scrollController: scrollController,
           style: style ?? state.context.theme.tileGroupStyle,
           cacheExtent: cacheExtent,
           maxHeight: maxHeight,
           dragStartBehavior: dragStartBehavior,
           physics: physics,
           count: count,
           divider: divider,
           label: label,
           enabled: enabled,
           description: description,
           error: switch (state.errorText) {
             _ when !enabled => null,
             final text? => errorBuilder(state.context, text),
             null => null,
           },
           semanticsLabel: semanticsLabel,
           tileBuilder: (context, index) {
             final child = tileBuilder(context, index);
             return child == null
                 ? null
                 : FSelectTileData<T>(
                     controller: selectController,
                     selected: selectController.contains(child.value),
                     child: child,
                   );
           },
         );
       },
     );