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> {
7676 ]),
7777 ),
7878 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 ),
79104 MaterialButton (
80105 color: Theme .of (context).accentColor,
81106 child: Text (
@@ -88,6 +113,7 @@ class _SignupFormState extends State<SignupForm> {
88113 } else {
89114 print ('Invalid' );
90115 }
116+ print (_formKey.currentState.value);
91117 },
92118 )
93119 ],
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ enum ControlAffinity { leading, trailing }
99///
1010/// This widget maintains the current state of the form field, so that updates
1111/// and validation errors are visually reflected in the UI.
12- abstract class FormBuilderField <T > extends FormField <T > {
12+ class FormBuilderField <T > extends FormField <T > {
1313 /// Used to reference the field within the form, or to reference form data
1414 /// after the form is submitted.
1515 final String name;
@@ -73,11 +73,14 @@ abstract class FormBuilderField<T> extends FormField<T> {
7373 validator: validator,
7474 );
7575
76+ /*@override
77+ FormBuilderFieldState<T> createState();*/
7678 @override
77- FormFieldState <T > createState ();
79+ FormBuilderFieldState <FormBuilderField <T >, T > createState () =>
80+ FormBuilderFieldState <FormBuilderField <T >, T >();
7881}
7982
80- abstract class FormBuilderFieldState <F extends FormBuilderField <T >, T >
83+ class FormBuilderFieldState <F extends FormBuilderField <T >, T >
8184 extends FormFieldState <T > {
8285 @override
8386 F get widget => super .widget as F ;
You can’t perform that action at this time.
0 commit comments