Skip to content

Instantly share code, notes, and snippets.

@rapPayne
Created October 21, 2020 22:42
Show Gist options
  • Save rapPayne/99d24ab0a8aec4e955cd77e9e86b9617 to your computer and use it in GitHub Desktop.
Save rapPayne/99d24ab0a8aec4e955cd77e9e86b9617 to your computer and use it in GitHub Desktop.
Validating a checkbox -- after
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