File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,31 @@ class _SignupFormState extends State<SignupForm> {
76
76
]),
77
77
),
78
78
const SizedBox (height: 10 ),
79
+ FormBuilderField <bool >(
80
+ name: 'test' ,
81
+ validator: FormBuilderValidators .compose ([
82
+ FormBuilderValidators .required (context),
83
+ FormBuilderValidators .equal (context, true ),
84
+ ]),
85
+ // initialValue: true,
86
+ decoration: InputDecoration (labelText: 'Accept Terms?' ),
87
+ builder: (FormFieldState <bool > field) {
88
+ return InputDecorator (
89
+ decoration: InputDecoration (
90
+ errorText: field.errorText,
91
+ ),
92
+ child: SwitchListTile (
93
+ title: Text (
94
+ 'I have read and accept the terms of service.' ),
95
+ onChanged: (bool value) {
96
+ field.didChange (value);
97
+ },
98
+ value: field.value ?? false ,
99
+ ),
100
+ );
101
+ },
102
+ ),
103
+ const SizedBox (height: 10 ),
79
104
MaterialButton (
80
105
color: Theme .of (context).accentColor,
81
106
child: Text (
@@ -88,6 +113,7 @@ class _SignupFormState extends State<SignupForm> {
88
113
} else {
89
114
print ('Invalid' );
90
115
}
116
+ print (_formKey.currentState.value);
91
117
},
92
118
)
93
119
],
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ enum ControlAffinity { leading, trailing }
9
9
///
10
10
/// This widget maintains the current state of the form field, so that updates
11
11
/// and validation errors are visually reflected in the UI.
12
- abstract class FormBuilderField <T > extends FormField <T > {
12
+ class FormBuilderField <T > extends FormField <T > {
13
13
/// Used to reference the field within the form, or to reference form data
14
14
/// after the form is submitted.
15
15
final String name;
@@ -73,11 +73,14 @@ abstract class FormBuilderField<T> extends FormField<T> {
73
73
validator: validator,
74
74
);
75
75
76
+ /*@override
77
+ FormBuilderFieldState<T> createState();*/
76
78
@override
77
- FormFieldState <T > createState ();
79
+ FormBuilderFieldState <FormBuilderField <T >, T > createState () =>
80
+ FormBuilderFieldState <FormBuilderField <T >, T >();
78
81
}
79
82
80
- abstract class FormBuilderFieldState <F extends FormBuilderField <T >, T >
83
+ class FormBuilderFieldState <F extends FormBuilderField <T >, T >
81
84
extends FormFieldState <T > {
82
85
@override
83
86
F get widget => super .widget as F ;
You can’t perform that action at this time.
0 commit comments