Skip to content

Commit c41e0b8

Browse files
committed
Allow adding InputBorder on DropdownField
1 parent c10d590 commit c41e0b8

File tree

1 file changed

+61
-29
lines changed

1 file changed

+61
-29
lines changed

lib/src/fields/form_builder_dropdown.dart

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FormBuilderDropdown extends StatefulWidget {
3131
this.readOnly = false,
3232
this.decoration = const InputDecoration(),
3333
this.isExpanded = true,
34-
this.isDense = false,
34+
this.isDense = true,
3535
this.elevation = 8,
3636
this.iconSize = 24.0,
3737
this.hint,
@@ -99,38 +99,70 @@ class _FormBuilderDropdownState extends State<FormBuilderDropdown> {
9999
return InputDecorator(
100100
decoration: widget.decoration.copyWith(
101101
errorText: field.errorText,
102-
border: InputBorder.none,
103102
),
104-
child: DropdownButton(
105-
isExpanded: widget.isExpanded,
106-
hint: widget.hint,
107-
items: widget.items,
108-
value: field.value,
109-
style: widget.style,
110-
isDense: widget.isDense,
111-
disabledHint: field.value != null
112-
? Text("${field.value.toString()}")
113-
: widget.disabledHint,
114-
elevation: widget.elevation,
115-
iconSize: widget.iconSize,
116-
icon: widget.icon,
117-
iconDisabledColor: widget.iconDisabledColor,
118-
iconEnabledColor: widget.iconEnabledColor,
119-
underline: widget.underline,
120-
onChanged: _readOnly
121-
? null
122-
: (value) {
123-
FocusScope.of(context).requestFocus(FocusNode());
124-
field.didChange(value);
125-
if (widget.onChanged != null) widget.onChanged(value);
126-
},
127-
//TODO: add icon, enabledColor, disabledColor
128-
/*icon: widget.icon,
129-
iconEnabledColor: widget.iconEnabledColor,
130-
iconDisabledColor: widget.iconDisabledColor,*/
103+
child: DropdownButtonHideUnderline(
104+
child: DropdownButton(
105+
isExpanded: widget.isExpanded,
106+
hint: widget.hint,
107+
items: widget.items,
108+
value: field.value,
109+
style: widget.style,
110+
isDense: widget.isDense,
111+
disabledHint: field.value != null
112+
? Text("${field.value.toString()}")
113+
: widget.disabledHint,
114+
elevation: widget.elevation,
115+
iconSize: widget.iconSize,
116+
icon: widget.icon,
117+
iconDisabledColor: widget.iconDisabledColor,
118+
iconEnabledColor: widget.iconEnabledColor,
119+
underline: widget.underline,
120+
onChanged: _readOnly
121+
? null
122+
: (value) {
123+
FocusScope.of(context).requestFocus(FocusNode());
124+
field.didChange(value);
125+
if (widget.onChanged != null) widget.onChanged(value);
126+
},
127+
),
131128
),
132129
);
133130
},
134131
);
135132
}
133+
134+
/*@override
135+
Widget build(BuildContext context) {
136+
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
137+
138+
return DropdownButtonFormField(
139+
key: _fieldKey,
140+
decoration: widget.decoration.copyWith(
141+
enabled: _readOnly ? false : true,
142+
),
143+
hint: widget.hint,
144+
items: widget.items,
145+
value: _initialValue,
146+
onChanged: _readOnly
147+
? null
148+
: (value) {
149+
FocusScope.of(context).requestFocus(FocusNode());
150+
if (widget.onChanged != null) widget.onChanged(value);
151+
},
152+
validator: (val) {
153+
for (int i = 0; i < widget.validators.length; i++) {
154+
if (widget.validators[i](val) != null)
155+
return widget.validators[i](val);
156+
}
157+
return null;
158+
},
159+
onSaved: (val) {
160+
if (widget.valueTransformer != null) {
161+
var transformed = widget.valueTransformer(val);
162+
_formState?.setAttributeValue(widget.attribute, transformed);
163+
} else
164+
_formState?.setAttributeValue(widget.attribute, val);
165+
},
166+
);
167+
}*/
136168
}

0 commit comments

Comments
 (0)