Skip to content

Commit 7c08c52

Browse files
committed
Fixed bug where TextField where initialValue from FormBuilder is ignored. Closes #370
1 parent e222582 commit 7c08c52

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/src/fields/form_builder_text_field.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ class FormBuilderTextField extends FormBuilderField {
127127
assert(enableInteractiveSelection != null),
128128
super(
129129
key: key,
130-
initialValue:
131-
controller != null ? controller.text : (initialValue ?? ''),
130+
initialValue: controller != null ? controller.text : initialValue,
132131
attribute: attribute,
133132
validator: validator,
134133
valueTransformer: valueTransformer,
@@ -165,7 +164,6 @@ class FormBuilderTextField extends FormBuilderField {
165164
textDirection: textDirection,
166165
textCapitalization: textCapitalization,
167166
autofocus: autofocus,
168-
// toolbarOptions: toolbarOptions,
169167
readOnly: readOnly,
170168
showCursor: showCursor,
171169
obscureText: obscureText,
@@ -207,7 +205,7 @@ class FormBuilderTextField extends FormBuilderField {
207205

208206
class _FormBuilderTextFieldState extends FormBuilderFieldState {
209207
@override
210-
FormBuilderTextField get widget => super.widget;
208+
FormBuilderTextField get widget => super.widget as FormBuilderTextField;
211209

212210
TextEditingController get _effectiveController =>
213211
widget.controller ?? _controller;
@@ -218,7 +216,7 @@ class _FormBuilderTextFieldState extends FormBuilderFieldState {
218216
void initState() {
219217
super.initState();
220218
if (widget.controller == null) {
221-
_controller = TextEditingController(text: widget.initialValue);
219+
_controller = TextEditingController(text: initialValue);
222220
} else {
223221
widget.controller.addListener(_handleControllerChanged);
224222
}
@@ -245,14 +243,15 @@ class _FormBuilderTextFieldState extends FormBuilderFieldState {
245243
@override
246244
void dispose() {
247245
widget.controller?.removeListener(_handleControllerChanged);
246+
_controller?.dispose();
248247
super.dispose();
249248
}
250249

251250
@override
252251
void reset() {
253252
super.reset();
254253
setState(() {
255-
_effectiveController.text = widget.initialValue ?? '';
254+
_effectiveController.text = initialValue ?? '';
256255
});
257256
}
258257

0 commit comments

Comments
 (0)