FormBuilderFilterChip<T> constructor

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

Creates field with chips that acts like a list checkboxes.

Implementation

FormBuilderFilterChip({
  super.autovalidateMode = AutovalidateMode.disabled,
  super.enabled,
  super.focusNode,
  super.onSaved,
  super.validator,
  super.decoration,
  super.key,
  super.initialValue,
  required super.name,
  super.restorationId,
  required this.options,
  this.alignment = WrapAlignment.start,
  this.avatarBorder = const CircleBorder(),
  this.backgroundColor,
  this.checkmarkColor,
  this.clipBehavior = Clip.none,
  this.crossAxisAlignment = WrapCrossAlignment.start,
  this.direction = Axis.horizontal,
  this.disabledColor,
  this.elevation,
  this.labelPadding,
  this.labelStyle,
  this.materialTapTargetSize,
  this.maxChips,
  this.padding,
  this.pressElevation,
  this.runAlignment = WrapAlignment.start,
  this.runSpacing = 0.0,
  this.selectedColor,
  this.selectedShadowColor,
  this.shadowColor,
  this.shape,
  this.showCheckmark = true,
  this.spacing = 0.0,
  this.textDirection,
  this.verticalDirection = VerticalDirection.down,
  super.onChanged,
  super.valueTransformer,
  super.onReset,
})  : assert((maxChips == null) || ((initialValue ?? []).length <= maxChips)),
      super(
        builder: (FormFieldState<List<T>?> field) {
          final state = field as _FormBuilderFilterChipState<T>;
          final fieldValue = field.value ?? [];

          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 (FormBuilderChipOption<T> option in options)
                  FilterChip(
                    label: option,
                    selected: fieldValue.contains(option.value),
                    avatar: option.avatar,
                    onSelected: state.enabled &&
                            (null == maxChips ||
                                fieldValue.length < maxChips ||
                                fieldValue.contains(option.value))
                        ? (selected) {
                            final currentValue = [...fieldValue];
                            selected
                                ? currentValue.add(option.value)
                                : currentValue.remove(option.value);

                            field.didChange(currentValue);
                          }
                        : null,
                    selectedColor: selectedColor,
                    disabledColor: disabledColor,
                    backgroundColor: backgroundColor,
                    shadowColor: shadowColor,
                    selectedShadowColor: selectedShadowColor,
                    elevation: elevation,
                    pressElevation: pressElevation,
                    materialTapTargetSize: materialTapTargetSize,
                    padding: padding,
                    shape: shape,
                    checkmarkColor: checkmarkColor,
                    clipBehavior: clipBehavior,
                    labelStyle: labelStyle,
                    showCheckmark: showCheckmark,
                    labelPadding: labelPadding,
                    avatarBorder: avatarBorder,
                  ),
              ],
            ),
          );
        },
      );