FormBuilderFilterChip<T> constructor

FormBuilderFilterChip<T>({
  1. Key? key,
  2. required String name,
  3. FormFieldValidator<List<T>>? validator,
  4. List<T> initialValue = const [],
  5. InputDecoration decoration = const InputDecoration(border: InputBorder.none, focusedBorder: InputBorder.none, enabledBorder: InputBorder.none, errorBorder: InputBorder.none, disabledBorder: InputBorder.none),
  6. ValueChanged<List<T>?>? onChanged,
  7. ValueTransformer<List<T>?>? valueTransformer,
  8. bool enabled = true,
  9. FormFieldSetter<List<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? padding,
  32. Color? checkmarkColor,
  33. Clip clipBehavior = Clip.none,
  34. TextStyle? labelStyle,
  35. bool showCheckmark = true,
  36. EdgeInsets? labelPadding,
  37. int? maxChips,
})

Creates field with chips that acts like a list checkboxes.

Implementation

FormBuilderFilterChip({
  Key? key,
  //From Super
  required String name,
  FormFieldValidator<List<T>>? validator,
  List<T> initialValue = const [],
  InputDecoration decoration = const InputDecoration(
    border: InputBorder.none,
    focusedBorder: InputBorder.none,
    enabledBorder: InputBorder.none,
    errorBorder: InputBorder.none,
    disabledBorder: InputBorder.none,
  ),
  ValueChanged<List<T>?>? onChanged,
  ValueTransformer<List<T>?>? valueTransformer,
  bool enabled = true,
  FormFieldSetter<List<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.padding,
  this.checkmarkColor,
  this.clipBehavior = Clip.none,
  this.labelStyle,
  this.showCheckmark = true,
  this.labelPadding,
  this.maxChips,
  // this.visualDensity,
})  : assert((maxChips == null) || (initialValue.length <= maxChips)),
      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<List<T>?> field) {
          final state = field as _FormBuilderFilterChipState<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)
                  FilterChip(
                    label: option,
                    selected: field.value!.contains(option.value),
                    onSelected: state.enabled &&
                            (null == maxChips ||
                                field.value!.length < maxChips ||
                                field.value!.contains(option.value))
                        ? (selected) {
                            final currentValue = [...field.value!];
                            if (selected) {
                              currentValue.add(option.value);
                            } else {
                              currentValue.remove(option.value);
                            }
                            state.requestFocus();
                            field.didChange(currentValue);
                          }
                        : null,
                    selectedColor: selectedColor,
                    disabledColor: disabledColor,
                    backgroundColor: backgroundColor,
                    shadowColor: shadowColor,
                    selectedShadowColor: selectedShadowColor,
                    // shape: shape,  //TODO: remove - latter flutter versions
                    elevation: elevation,
                    pressElevation: pressElevation,
                    materialTapTargetSize: materialTapTargetSize,
                    padding: padding,
                    checkmarkColor: checkmarkColor,
                    clipBehavior: clipBehavior,
                    labelStyle: labelStyle,
                    showCheckmark: showCheckmark,
                    labelPadding: labelPadding,
                    // visualDensity: visualDensity,
                  ),
              ],
            ),
          );
        },
      );