FormBuilderFilterChip<T> constructor
FormBuilderFilterChip<T> ({
- AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- bool enabled = true,
- FocusNode? focusNode,
- FormFieldSetter<
List< ? onSaved,T> > - FormFieldValidator<
List< ? validator,T> > - InputDecoration decoration = const InputDecoration(),
- Key? key,
- List<
T> ? initialValue, - required String name,
- required List<
FormBuilderChipOption< options,T> > - WrapAlignment alignment = WrapAlignment.start,
- ShapeBorder avatarBorder = const CircleBorder(),
- Color? backgroundColor,
- Color? checkmarkColor,
- Clip clipBehavior = Clip.none,
- WrapCrossAlignment crossAxisAlignment = WrapCrossAlignment.start,
- Axis direction = Axis.horizontal,
- Color? disabledColor,
- double? elevation,
- EdgeInsets? labelPadding,
- TextStyle? labelStyle,
- MaterialTapTargetSize? materialTapTargetSize,
- int? maxChips,
- EdgeInsets? padding,
- double? pressElevation,
- WrapAlignment runAlignment = WrapAlignment.start,
- double runSpacing = 0.0,
- Color? selectedColor,
- Color? selectedShadowColor,
- Color? shadowColor,
- OutlinedBorder? shape,
- bool shouldRequestFocus = false,
- bool showCheckmark = true,
- double spacing = 0.0,
- TextDirection? textDirection,
- VerticalDirection verticalDirection = VerticalDirection.down,
- ValueChanged<
List< ? onChanged,T> ?> - ValueTransformer<
List< ? valueTransformer,T> ?> - 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,
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.shouldRequestFocus = false,
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];
if (selected) {
currentValue.add(option.value);
} else {
currentValue.remove(option.value);
}
if (shouldRequestFocus) {
state.requestFocus();
}
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,
),
],
),
);
},
);