FSelectTileGroup<T>.builder constructor

FSelectTileGroup<T>.builder({
  1. required FSelectGroupController<T> groupController,
  2. required FSelectTile<T>? tileBuilder(
    1. BuildContext,
    2. int
    ),
  3. int? count,
  4. ScrollController? scrollController,
  5. FTileGroupStyle? style,
  6. double? cacheExtent,
  7. double maxHeight = double.infinity,
  8. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  9. FTileDivider divider = FTileDivider.indented,
  10. Widget? label,
  11. Widget? description,
  12. Widget errorBuilder(
    1. BuildContext,
    2. String
    ) = _errorBuilder,
  13. String? semanticLabel,
  14. FormFieldSetter<Set<T>>? onSaved,
  15. FormFieldValidator<Set<T>>? validator,
  16. Set<T>? initialValue,
  17. String? forceErrorText,
  18. bool enabled = true,
  19. AutovalidateMode? autovalidateMode,
  20. String? restorationId,
  21. Key? key,
})

Creates a FSelectTileGroup 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

FSelectTileGroup.builder({
  required this.groupController,
  required FSelectTile<T>? Function(BuildContext, int) tileBuilder,
  int? count,
  this.scrollController,
  this.style,
  this.cacheExtent,
  this.maxHeight = double.infinity,
  this.dragStartBehavior = DragStartBehavior.start,
  this.divider = FTileDivider.indented,
  this.label,
  this.description,
  this.errorBuilder = _errorBuilder,
  this.semanticLabel,
  super.onSaved,
  super.validator,
  super.initialValue,
  super.forceErrorText,
  super.enabled = true,
  super.autovalidateMode,
  super.restorationId,
  super.key,
}) : super(
        builder: (field) {
          final state = field as _State;
          final groupStyle = style ?? state.context.theme.tileGroupStyle;
          final (labelState, error) = switch (state.errorText) {
            _ when !enabled => (FLabelState.disabled, null),
            final text? => (FLabelState.error, errorBuilder(state.context, text)),
            null => (FLabelState.enabled, null),
          };

          return FTileGroup.builder(
            controller: scrollController,
            style: groupStyle,
            cacheExtent: cacheExtent,
            maxHeight: maxHeight,
            dragStartBehavior: dragStartBehavior,
            count: count,
            divider: divider,
            label: label,
            enabled: enabled,
            description: description,
            error: error,
            semanticLabel: semanticLabel,
            tileBuilder: (context, index) {
              final child = tileBuilder(context, index);
              return child == null
                  ? null
                  : FSelectTileData<T>(
                      controller: groupController,
                      selected: groupController.contains(child.value),
                      child: child,
                    );
            },
          );
        },
      );