FSelectTileGroup<T>.builder constructor
FSelectTileGroup<T>.builder ({
- required FSelectGroupController<
T> groupController, - required FSelectTile<
T> ? tileBuilder(), - int? count,
- ScrollController? scrollController,
- FTileGroupStyle? style,
- double? cacheExtent,
- double maxHeight = double.infinity,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- FTileDivider divider = FTileDivider.indented,
- Widget? label,
- Widget? description,
- Widget errorBuilder() = _errorBuilder,
- String? semanticLabel,
- FormFieldSetter<
Set< ? onSaved,T> > - FormFieldValidator<
Set< ? validator,T> > - Set<
T> ? initialValue, - String? forceErrorText,
- bool enabled = true,
- AutovalidateMode? autovalidateMode,
- String? restorationId,
- 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
ifcount
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 andtileBuilder
always provides a zero-size widget, i.e. SizedBox(). If possible, provide tiles with non-zero size, return null from builder, or setcount
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,
);
},
);
},
);