child: CheckboxListTile(
title: Text('Eggs'),
controlAffinity: ListTileControlAffinity.platform,
value: _checked,
onChanged: (bool value){
setState(() {
_checked = value;
});
},
activeColor: Colors.white,
checkColor: Colors.red[900],
),
This is the code i used. The error is showing at the _checked. It says that _checked is not defined. A new user to flutter here.
It says that _checked is not defined
You properly miss to define _checked
.
bool _checked = false;
You actually need to initialize a variable in the beginning. Maybe you can do it by initializing it like:
bool _value = true //or false according to your program
or you can do this in the screen's or page's:
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override
Widget build(BuildContext context) {
return CheckboxListTile(
title: const Text('Animate Slowly'),
value: timeDilation != 1.0,
onChanged: (bool value) {
setState(() {
timeDilation = value ? 10.0 : 1.0;
});
},
);
}
}
Basically, you are getting this error as you haven't initialized _checked
variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.