@@ -13,6 +13,7 @@ class FormBuilderFilterChip extends StatefulWidget {
13
13
final ValueTransformer valueTransformer;
14
14
final List <FormBuilderFieldOption > options;
15
15
final FormFieldSetter onSaved;
16
+
16
17
// FilterChip Settings
17
18
final double elevation, pressElevation;
18
19
final Color selectedColor,
@@ -22,6 +23,7 @@ class FormBuilderFilterChip extends StatefulWidget {
22
23
shadowColor;
23
24
final ShapeBorder shape;
24
25
final MaterialTapTargetSize materialTapTargetSize;
26
+
25
27
// Wrap Settings
26
28
final Axis direction;
27
29
final WrapAlignment alignment;
@@ -30,36 +32,50 @@ class FormBuilderFilterChip extends StatefulWidget {
30
32
final double runSpacing, spacing;
31
33
final TextDirection textDirection;
32
34
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;
33
42
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);
63
79
64
80
@override
65
81
_FormBuilderFilterChipState createState () => _FormBuilderFilterChipState ();
@@ -93,75 +109,87 @@ class _FormBuilderFilterChipState extends State<FormBuilderFilterChip> {
93
109
_readOnly = (_formState? .readOnly == true ) ? true : widget.readOnly;
94
110
95
111
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;
153
160
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);
158
165
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
+ );
166
194
}
167
195
}
0 commit comments