Skip to content

Commit 14f41a9

Browse files
committed
added option to showCheckmark for FormBuilderFilterChip, along with other options. Closes #260
1 parent d0bf1dc commit 14f41a9

File tree

1 file changed

+125
-97
lines changed

1 file changed

+125
-97
lines changed

lib/src/fields/form_builder_chips_filter.dart

Lines changed: 125 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class FormBuilderFilterChip extends StatefulWidget {
1313
final ValueTransformer valueTransformer;
1414
final List<FormBuilderFieldOption> options;
1515
final FormFieldSetter onSaved;
16+
1617
// FilterChip Settings
1718
final double elevation, pressElevation;
1819
final Color selectedColor,
@@ -22,6 +23,7 @@ class FormBuilderFilterChip extends StatefulWidget {
2223
shadowColor;
2324
final ShapeBorder shape;
2425
final MaterialTapTargetSize materialTapTargetSize;
26+
2527
// Wrap Settings
2628
final Axis direction;
2729
final WrapAlignment alignment;
@@ -30,36 +32,50 @@ class FormBuilderFilterChip extends StatefulWidget {
3032
final double runSpacing, spacing;
3133
final TextDirection textDirection;
3234
final VerticalDirection verticalDirection;
35+
final EdgeInsets padding;
36+
final Color checkmarkColor;
37+
final Clip clipBehavior;
38+
final TextStyle labelStyle;
39+
final bool showCheckmark;
40+
final EdgeInsets labelPadding;
41+
// final VisualDensity visualDensity;
3342

34-
FormBuilderFilterChip(
35-
{Key key,
36-
@required this.attribute,
37-
@required this.options,
38-
this.initialValue,
39-
this.validators = const [],
40-
this.readOnly = false,
41-
this.decoration = const InputDecoration(),
42-
this.onChanged,
43-
this.onSaved,
44-
this.valueTransformer,
45-
this.selectedColor,
46-
this.disabledColor,
47-
this.backgroundColor,
48-
this.shadowColor,
49-
this.selectedShadowColor,
50-
this.shape,
51-
this.elevation,
52-
this.pressElevation,
53-
this.materialTapTargetSize,
54-
this.direction = Axis.horizontal,
55-
this.alignment = WrapAlignment.start,
56-
this.crossAxisAlignment = WrapCrossAlignment.start,
57-
this.runAlignment = WrapAlignment.start,
58-
this.runSpacing = 0.0,
59-
this.spacing = 0.0,
60-
this.textDirection,
61-
this.verticalDirection = VerticalDirection.down})
62-
: super(key: key);
43+
FormBuilderFilterChip({
44+
Key key,
45+
@required this.attribute,
46+
@required this.options,
47+
this.initialValue,
48+
this.validators = const [],
49+
this.readOnly = false,
50+
this.decoration = const InputDecoration(),
51+
this.onChanged,
52+
this.onSaved,
53+
this.valueTransformer,
54+
this.selectedColor,
55+
this.disabledColor,
56+
this.backgroundColor,
57+
this.shadowColor,
58+
this.selectedShadowColor,
59+
this.shape,
60+
this.elevation,
61+
this.pressElevation,
62+
this.materialTapTargetSize,
63+
this.direction = Axis.horizontal,
64+
this.alignment = WrapAlignment.start,
65+
this.crossAxisAlignment = WrapCrossAlignment.start,
66+
this.runAlignment = WrapAlignment.start,
67+
this.runSpacing = 0.0,
68+
this.spacing = 0.0,
69+
this.textDirection,
70+
this.verticalDirection = VerticalDirection.down,
71+
this.padding,
72+
this.checkmarkColor,
73+
this.clipBehavior = Clip.none,
74+
this.labelStyle,
75+
this.showCheckmark = true,
76+
this.labelPadding,
77+
// this.visualDensity,
78+
}) : super(key: key);
6379

6480
@override
6581
_FormBuilderFilterChipState createState() => _FormBuilderFilterChipState();
@@ -93,75 +109,87 @@ class _FormBuilderFilterChipState extends State<FormBuilderFilterChip> {
93109
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
94110

95111
return FormField(
96-
key: _fieldKey,
97-
enabled: !_readOnly,
98-
initialValue: _initialValue ?? [],
99-
validator: (val) {
100-
for (int i = 0; i < widget.validators.length; i++) {
101-
if (widget.validators[i](val) != null)
102-
return widget.validators[i](val);
103-
}
104-
return null;
105-
},
106-
onSaved: (val) {
107-
var transformed;
108-
if (widget.valueTransformer != null) {
109-
transformed = widget.valueTransformer(val);
110-
_formState?.setAttributeValue(widget.attribute, transformed);
111-
} else
112-
_formState?.setAttributeValue(widget.attribute, val);
113-
if (widget.onSaved != null) {
114-
widget.onSaved(transformed ?? val);
115-
}
116-
},
117-
builder: (FormFieldState<dynamic> field) {
118-
return InputDecorator(
119-
decoration: widget.decoration.copyWith(
120-
enabled: !_readOnly,
121-
errorText: field.errorText,
122-
),
123-
child: Wrap(
124-
direction: widget.direction,
125-
alignment: widget.alignment,
126-
crossAxisAlignment: widget.crossAxisAlignment,
127-
runAlignment: widget.runAlignment,
128-
runSpacing: widget.runSpacing,
129-
spacing: widget.spacing,
130-
textDirection: widget.textDirection,
131-
verticalDirection: widget.verticalDirection,
132-
children: <Widget>[
133-
for (FormBuilderFieldOption option in widget.options)
134-
FilterChip(
135-
selectedColor: widget.selectedColor,
136-
disabledColor: widget.disabledColor,
137-
backgroundColor: widget.backgroundColor,
138-
shadowColor: widget.shadowColor,
139-
selectedShadowColor: widget.selectedShadowColor,
140-
shape: widget.shape,
141-
elevation: widget.elevation,
142-
pressElevation: widget.pressElevation,
143-
materialTapTargetSize: widget.materialTapTargetSize,
144-
label: option.child,
145-
selected: field.value.contains(option.value),
146-
onSelected: _readOnly
147-
? null
148-
: (bool selected) {
149-
setState(() {
150-
FocusScope.of(context)
151-
.requestFocus(FocusNode());
152-
var currentValue = field.value;
112+
key: _fieldKey,
113+
enabled: !_readOnly,
114+
initialValue: _initialValue ?? [],
115+
validator: (val) {
116+
for (int i = 0; i < widget.validators.length; i++) {
117+
if (widget.validators[i](val) != null)
118+
return widget.validators[i](val);
119+
}
120+
return null;
121+
},
122+
onSaved: (val) {
123+
var transformed;
124+
if (widget.valueTransformer != null) {
125+
transformed = widget.valueTransformer(val);
126+
_formState?.setAttributeValue(widget.attribute, transformed);
127+
} else
128+
_formState?.setAttributeValue(widget.attribute, val);
129+
if (widget.onSaved != null) {
130+
widget.onSaved(transformed ?? val);
131+
}
132+
},
133+
builder: (FormFieldState<dynamic> field) {
134+
return InputDecorator(
135+
decoration: widget.decoration.copyWith(
136+
enabled: !_readOnly,
137+
errorText: field.errorText,
138+
),
139+
child: Wrap(
140+
direction: widget.direction,
141+
alignment: widget.alignment,
142+
crossAxisAlignment: widget.crossAxisAlignment,
143+
runAlignment: widget.runAlignment,
144+
runSpacing: widget.runSpacing,
145+
spacing: widget.spacing,
146+
textDirection: widget.textDirection,
147+
verticalDirection: widget.verticalDirection,
148+
children: <Widget>[
149+
for (FormBuilderFieldOption option in widget.options)
150+
FilterChip(
151+
label: option.child,
152+
selected: field.value.contains(option.value),
153+
onSelected: _readOnly
154+
? null
155+
: (bool selected) {
156+
setState(
157+
() {
158+
FocusScope.of(context).requestFocus(FocusNode());
159+
var currentValue = field.value;
153160

154-
if (selected)
155-
currentValue.add(option.value);
156-
else
157-
currentValue.remove(option.value);
161+
if (selected)
162+
currentValue.add(option.value);
163+
else
164+
currentValue.remove(option.value);
158165

159-
field.didChange(currentValue);
160-
if (widget.onChanged != null)
161-
widget.onChanged(currentValue);
162-
});
163-
})
164-
]));
165-
});
166+
field.didChange(currentValue);
167+
if (widget.onChanged != null)
168+
widget.onChanged(currentValue);
169+
},
170+
);
171+
},
172+
selectedColor: widget.selectedColor,
173+
disabledColor: widget.disabledColor,
174+
backgroundColor: widget.backgroundColor,
175+
shadowColor: widget.shadowColor,
176+
selectedShadowColor: widget.selectedShadowColor,
177+
shape: widget.shape,
178+
elevation: widget.elevation,
179+
pressElevation: widget.pressElevation,
180+
materialTapTargetSize: widget.materialTapTargetSize,
181+
padding: widget.padding,
182+
checkmarkColor: widget.checkmarkColor,
183+
clipBehavior: widget.clipBehavior,
184+
labelStyle: widget.labelStyle,
185+
showCheckmark: widget.showCheckmark,
186+
labelPadding: widget.labelPadding,
187+
// visualDensity: widget.visualDensity,
188+
),
189+
],
190+
),
191+
);
192+
},
193+
);
166194
}
167195
}

0 commit comments

Comments
 (0)