@@ -38,8 +38,8 @@ class FormBuilderField<T> extends FormField<T> {
38
38
/// Called when the field value is changed.
39
39
final ValueChanged <T ?>? onChanged;
40
40
41
- /// The border, labels, icons, and styles used to decorate the field.
42
- final InputDecoration decoration;
41
+ // // / The border, labels, icons, and styles used to decorate the field.
42
+ // final InputDecoration decoration;
43
43
44
44
/// Called when the field value is reset.
45
45
final VoidCallback ? onReset;
@@ -60,11 +60,27 @@ class FormBuilderField<T> extends FormField<T> {
60
60
required this .name,
61
61
this .valueTransformer,
62
62
this .onChanged,
63
- this .decoration = const InputDecoration (),
64
63
this .onReset,
65
64
this .focusNode,
66
65
});
67
66
67
+ const factory FormBuilderField .decoration ({
68
+ Key ? key,
69
+ void Function (T ? )? onSaved,
70
+ T ? initialValue,
71
+ AutovalidateMode ? autovalidateMode,
72
+ bool enabled,
73
+ String ? Function (T ? )? validator,
74
+ String ? restorationId,
75
+ required Widget Function (FormFieldState <T >) builder,
76
+ required String name,
77
+ ValueTransformer <T ?>? valueTransformer,
78
+ ValueChanged <T ?>? onChanged,
79
+ VoidCallback ? onReset,
80
+ FocusNode ? focusNode,
81
+ InputDecoration decoration,
82
+ }) = FormBuilderFieldDecoration ;
83
+
68
84
@override
69
85
FormBuilderFieldState <FormBuilderField <T >, T > createState () =>
70
86
FormBuilderFieldState <FormBuilderField <T >, T >();
@@ -98,12 +114,10 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
98
114
String ? get errorText => super .errorText ?? _customErrorText;
99
115
100
116
@override
101
- bool get hasError =>
102
- super .hasError || decoration.errorText != null || errorText != null ;
117
+ bool get hasError => super .hasError || errorText != null ;
103
118
104
119
@override
105
- bool get isValid =>
106
- super .isValid && decoration.errorText == null && errorText == null ;
120
+ bool get isValid => super .isValid && errorText == null ;
107
121
108
122
bool get enabled => widget.enabled && (_formBuilderState? .enabled ?? true );
109
123
bool get _readOnly => ! (_formBuilderState? .widget.skipDisabled ?? false );
@@ -124,12 +138,12 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
124
138
/// The field is focused by user or by logic code
125
139
bool get isTouched => _touched;
126
140
127
- InputDecoration get decoration => widget.decoration.copyWith (
128
- errorText: widget.enabled || _readOnly
129
- ? widget.decoration.errorText ?? errorText
130
- : null ,
131
- enabled: widget.enabled || _readOnly,
132
- );
141
+ // InputDecoration get decoration => widget.decoration.copyWith(
142
+ // errorText: widget.enabled || _readOnly
143
+ // ? widget.decoration.errorText ?? errorText
144
+ // : null,
145
+ // enabled: widget.enabled || _readOnly,
146
+ // );
133
147
134
148
void registerTransformer (Map <String , Function > map) {
135
149
final fun = widget.valueTransformer;
@@ -298,3 +312,47 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
298
312
Scrollable .ensureVisible (context);
299
313
}
300
314
}
315
+
316
+ class FormBuilderFieldDecoration <T > extends FormBuilderField <T > {
317
+ const FormBuilderFieldDecoration ({
318
+ super .key,
319
+ super .onSaved,
320
+ super .initialValue,
321
+ super .autovalidateMode,
322
+ super .enabled = true ,
323
+ super .validator,
324
+ super .restorationId,
325
+ required super .name,
326
+ super .valueTransformer,
327
+ super .onChanged,
328
+ super .onReset,
329
+ super .focusNode,
330
+ required super .builder,
331
+ this .decoration = const InputDecoration (),
332
+ });
333
+ final InputDecoration decoration;
334
+
335
+ @override
336
+ FormBuilderFieldDecorationState <FormBuilderFieldDecoration <T >, T >
337
+ createState () =>
338
+ FormBuilderFieldDecorationState <FormBuilderFieldDecoration <T >, T >();
339
+ }
340
+
341
+ class FormBuilderFieldDecorationState <F extends FormBuilderFieldDecoration <T >,
342
+ T > extends FormBuilderFieldState <FormBuilderField <T >, T > {
343
+ @override
344
+ F get widget => super .widget as F ;
345
+
346
+ InputDecoration get decoration => widget.decoration.copyWith (
347
+ errorText: widget.enabled || _readOnly
348
+ ? widget.decoration.errorText ?? errorText
349
+ : null ,
350
+ enabled: widget.enabled || _readOnly,
351
+ );
352
+
353
+ @override
354
+ bool get hasError => super .hasError || widget.decoration.errorText != null ;
355
+
356
+ @override
357
+ bool get isValid => super .isValid && widget.decoration.errorText == null ;
358
+ }
0 commit comments