[英]Hi i have been trying to use CheckBoxListTile in Flutter
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.
错误显示在 _checked 中。 It says that _checked is not defined.
它说 _checked 未定义。 A new user to flutter here.
一个新用户来这里飘。
It says that _checked is not defined
它说 _checked 未定义
You properly miss to define _checked
.您正确地错过了定义
_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.基本上,您会收到此错误,因为您尚未初始化
_checked
变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.