Checkbox(
value: good,
onChanged: (val) {
setState(() {
good = val;
});
}),
There is a red line under the val good = val
, what is the reason?
I didn't forget to write above bool good = false;
CodePudding user response:
onChanged
provide nullable bool
, define as
{required void Function(bool?)? onChanged}
you can provide false on null case like
onChanged: (val) {
setState(() {
good = val??false;
});
}
Find more about null-safety
CodePudding user response:
onChanged: (val) {
setState(() {
good = !good;
});
}
With this you can use switch good value from true to false or false to true every time you trigger this function