@@ -71,12 +71,17 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
71
71
FormBuilderState ? _formBuilderState;
72
72
bool _touched = false ;
73
73
bool _dirty = false ;
74
+
75
+ /// The focus node that is used to focus this field.
74
76
late FocusNode effectiveFocusNode;
77
+
78
+ /// The focus attachment for the [effectiveFocusNode] .
75
79
FocusAttachment ? focusAttachment;
76
80
77
81
@override
78
82
F get widget => super .widget as F ;
79
83
84
+ /// Returns the parent [FormBuilderState] if it exists.
80
85
FormBuilderState ? get formState => _formBuilderState;
81
86
82
87
/// Returns the initial value, which may be declared at the field, or by the
@@ -91,18 +96,33 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
91
96
widget.valueTransformer == null ? value : widget.valueTransformer !(value);
92
97
93
98
@override
99
+
100
+ /// Returns the current error text,
101
+ /// which may be a validation error or a custom error text.
94
102
String ? get errorText => super .errorText ?? _customErrorText;
95
103
96
104
@override
105
+
106
+ /// Returns `true` if the field has an error or has a custom error text.
97
107
bool get hasError => super .hasError || errorText != null ;
98
108
99
109
@override
110
+
111
+ /// Returns `true` if the field is valid and has no custom error text.
100
112
bool get isValid => super .isValid && _customErrorText == null ;
101
113
114
+ /// Returns `true` if the field is valid.
102
115
bool get valueIsValid => super .isValid;
116
+
117
+ /// Returns `true` if the field has an error.
103
118
bool get valueHasError => super .hasError;
104
119
120
+ /// Returns `true` if the field is enabled and the parent FormBuilder is enabled.
105
121
bool get enabled => widget.enabled && (_formBuilderState? .enabled ?? true );
122
+
123
+ /// Returns `true` if the field is read only.
124
+ ///
125
+ /// See [FormBuilder.skipDisabled] for more information.
106
126
bool get readOnly => ! (_formBuilderState? .widget.skipDisabled ?? false );
107
127
108
128
/// Will be true if the field is dirty
@@ -199,6 +219,10 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
199
219
}
200
220
201
221
@override
222
+
223
+ /// Reset field value to initial value
224
+ ///
225
+ /// Also reset custom error text if exists, and set [isDirty] to `false` .
202
226
void reset () {
203
227
super .reset ();
204
228
didChange (initialValue);
@@ -276,10 +300,12 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
276
300
);
277
301
}
278
302
303
+ /// Focus field
279
304
void focus () {
280
305
FocusScope .of (context).requestFocus (effectiveFocusNode);
281
306
}
282
307
308
+ /// Scroll to show field
283
309
void ensureScrollableVisibility () {
284
310
Scrollable .ensureVisible (context);
285
311
}
0 commit comments