FormBuilderFilterChip<T> constructor
FormBuilderFilterChip<T> ({
- Key? key,
- required String name,
- FormFieldValidator<
List< ? validator,T> > - 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< ? onChanged,T> ?> - ValueTransformer<
List< ? valueTransformer,T> ?> - bool enabled = true,
- FormFieldSetter<
List< ? onSaved,T> > - AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
- VoidCallback? onReset,
- FocusNode? focusNode,
- required List<
FormBuilderFieldOption< options,T> > - Color? selectedColor,
- Color? disabledColor,
- Color? backgroundColor,
- Color? shadowColor,
- Color? selectedShadowColor,
- OutlinedBorder? shape,
- double? elevation,
- double? pressElevation,
- MaterialTapTargetSize? materialTapTargetSize,
- Axis direction = Axis.horizontal,
- WrapAlignment alignment = WrapAlignment.start,
- WrapCrossAlignment crossAxisAlignment = WrapCrossAlignment.start,
- WrapAlignment runAlignment = WrapAlignment.start,
- double runSpacing = 0.0,
- double spacing = 0.0,
- TextDirection? textDirection,
- VerticalDirection verticalDirection = VerticalDirection.down,
- EdgeInsets? padding,
- Color? checkmarkColor,
- Clip clipBehavior = Clip.none,
- TextStyle? labelStyle,
- bool showCheckmark = true,
- EdgeInsets? labelPadding,
- 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,
),
],
),
);
},
);