FSelectGroup<T> constructor

FSelectGroup<T>({
  1. required FSelectGroupController<T> controller,
  2. required List<FSelectGroupItem<T>> items,
  3. FSelectGroupStyle? style,
  4. Widget? label,
  5. Widget? description,
  6. Widget errorBuilder(
    1. BuildContext,
    2. String
    ) = _errorBuilder,
  7. FormFieldSetter<Set<T>>? onSaved,
  8. FormFieldValidator<Set<T>>? validator,
  9. Set<T>? initialValue,
  10. String? forceErrorText,
  11. bool enabled = true,
  12. AutovalidateMode? autovalidateMode,
  13. String? restorationId,
  14. Key? key,
})

Creates a FSelectGroup.

Implementation

FSelectGroup({
  required this.controller,
  required this.items,
  this.style,
  this.label,
  this.description,
  this.errorBuilder = _errorBuilder,
  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.selectGroupStyle;
          final (labelState, error) = switch (state.errorText) {
            _ when !enabled => (FLabelState.disabled, null),
            final text? => (FLabelState.error, errorBuilder(state.context, text)),
            null => (FLabelState.enabled, null),
          };

          return FLabel(
            axis: Axis.vertical,
            state: labelState,
            style: groupStyle.labelStyle,
            label: label,
            description: description,
            error: error,
            child: Column(
              children: [
                for (final child in items)
                  FSelectGroupItemData<T>(
                    controller: controller,
                    style: groupStyle,
                    selected: controller.contains(child.value),
                    child: child,
                  ),
              ],
            ),
          );
        },
      );