没有三态属性,我无法创建复选框小部件,此代码会产生错误:
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Lunes'),
Checkbox(
value: monday,
onChanged: (bool value){
setState(() {
monday = value;
});
},
)
],
),
此代码可以正常工作:
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Lunes'),
Checkbox(
tristate: true,
value: monday,
onChanged: (bool value){
setState(() {
monday = value;
});
},
)
],
),
为什么我需要三态?
答案 0 :(得分:0)
“星期一”必须为非null(布尔值)。我认为它在定义时或在initState()中尚未初始化,但是您似乎没有显示该代码。