FormBuilderChoiceChip<T> constructor

FormBuilderChoiceChip<T>({
  1. Key? key,
  2. required String name,
  3. FormFieldValidator<T>? validator,
  4. T? initialValue,
  5. InputDecoration decoration = const InputDecoration(),
  6. ValueChanged<T?>? onChanged,
  7. ValueTransformer<T?>? valueTransformer,
  8. bool enabled = true,
  9. FormFieldSetter<T>? onSaved,
  10. AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
  11. VoidCallback? onReset,
  12. FocusNode? focusNode,
  13. required List<FormBuilderFieldOption<T>> options,
  14. Color? selectedColor,
  15. Color? disabledColor,
  16. Color? backgroundColor,
  17. Color? shadowColor,
  18. Color? selectedShadowColor,
  19. OutlinedBorder? shape,
  20. double? elevation,
  21. double? pressElevation,
  22. MaterialTapTargetSize? materialTapTargetSize,
  23. Axis direction = Axis.horizontal,
  24. WrapAlignment alignment = WrapAlignment.start,
  25. WrapCrossAlignment crossAxisAlignment = WrapCrossAlignment.start,
  26. WrapAlignment runAlignment = WrapAlignment.start,
  27. double runSpacing = 0.0,
  28. double spacing = 0.0,
  29. TextDirection? textDirection,
  30. VerticalDirection verticalDirection = VerticalDirection.down,
  31. EdgeInsets? labelPadding,
  32. TextStyle? labelStyle,
  33. EdgeInsets? padding,
  34. VisualDensity? visualDensity,
})

Creates a list of Chips that acts like radio buttons

Implementation

FormBuilderChoiceChip({
  Key? key,
  //From Super
  required String name,
  FormFieldValidator<T>? validator,
  T? initialValue,
  InputDecoration decoration = const InputDecoration(),
  ValueChanged<T?>? onChanged,
  ValueTransformer<T?>? valueTransformer,
  bool enabled = true,
  FormFieldSetter<T>? onSaved,
  AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
  VoidCallback? onReset,
  FocusNode? focusNode,
  required this.options,
  this.selectedColor,
  this.disabledColor,
  this.backgroundColor,
  this.shadowColor,
  this.selectedShadowColor,
  this.shape,
  this.elevation,
  this.pressElevation,
  this.materialTapTargetSize,
  this.direction = Axis.horizontal,
  this.alignment = WrapAlignment.start,
  this.crossAxisAlignment = WrapCrossAlignment.start,
  this.runAlignment = WrapAlignment.start,
  this.runSpacing = 0.0,
  this.spacing = 0.0,
  this.textDirection,
  this.verticalDirection = VerticalDirection.down,
  this.labelPadding,
  this.labelStyle,
  this.padding,
  this.visualDensity,
}) : super(
          key: key,
          initialValue: initialValue,
          name: name,
          validator: validator,
          valueTransformer: valueTransformer,
          onChanged: onChanged,
          autovalidateMode: autovalidateMode,
          onSaved: onSaved,
          enabled: enabled,
          onReset: onReset,
          decoration: decoration,
          focusNode: focusNode,
          builder: (FormFieldState<T?> field) {
            final state = field as _FormBuilderChoiceChipState<T>;

            return InputDecorator(
              decoration: state.decoration,
              child: Wrap(
                direction: direction,
                alignment: alignment,
                crossAxisAlignment: crossAxisAlignment,
                runAlignment: runAlignment,
                runSpacing: runSpacing,
                spacing: spacing,
                textDirection: textDirection,
                verticalDirection: verticalDirection,
                children: <Widget>[
                  for (FormBuilderFieldOption<T> option in options)
                    ChoiceChip(
                      label: option,
                      selected: field.value == option.value,
                      onSelected: state.enabled
                          ? (selected) {
                              final choice = selected ? option.value : null;
                              state.requestFocus();
                              state.didChange(choice);
                            }
                          : null,
                      selectedColor: selectedColor,
                      disabledColor: disabledColor,
                      backgroundColor: backgroundColor,
                      shadowColor: shadowColor,
                      selectedShadowColor: selectedShadowColor,
                      // shape: shape,
                      elevation: elevation,
                      pressElevation: pressElevation,
                      materialTapTargetSize: materialTapTargetSize,
                      labelStyle: labelStyle,
                      labelPadding: labelPadding,
                      padding: padding,
                      visualDensity: visualDensity,
                    ),
                ],
              ),
            );
          });