Created
October 21, 2020 22:42
-
-
Save rapPayne/99d24ab0a8aec4e955cd77e9e86b9617 to your computer and use it in GitHub Desktop.
Validating a checkbox -- after
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Widget get _buildAgreeToTermsField { | |
// TODO 8: Wrap the Column with a FormField<bool> | |
return FormField<bool>( | |
// 1 | |
initialValue: _agree, | |
// 2 | |
builder: (FormFieldState<bool> state) { | |
return Column( | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
Checkbox( | |
// 3 | |
value: state.value, | |
onChanged: (bool val) => setState(() { | |
// 4 | |
_agree = val; | |
// 5 | |
state.didChange(val); | |
}), | |
), | |
const Text("I agree to the terms."), | |
], | |
), | |
// 6 | |
state.errorText == null | |
? Text("") | |
: Text(state.errorText, style: TextStyle(color: Colors.red)), | |
], | |
); | |
}, | |
// 7 | |
validator: (val) => _validateTerms(_agree), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment