android - 颤振复选框:当我勾选一个元素时,所有其他元素也被选中
问题描述
在我的这部分代码中,当我勾选 checkboxlist 的一个元素时,所有其他元素也都被选中。
我尝试将索引放在 _State[index] 上,但不起作用。
FutureBuilder<List<Map>>(
future: fetchUsersFromDatabase(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CheckboxListTile(
value:_State,
title: new Text(
snapshot.data[index]['checkcode'] +
",Tk" +
snapshot.data[index]['amount'].toString(),
style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0)),
activeColor: Colors.blue,
onChanged: (b) {
setState(() {
_State= !_State;
});
}),
new Divider(),
],
);
});
} else if (snapshot.hasError) {
return new Text("${snapshot.error}");
}
}
期望分别选择列表的每个元素。
解决方案
不要使用 _state ,而是尝试直接将值传递给特定的图块
onChanged: (bool value) {
setState(() {
widget.formItems[widget.count]['list'][i]['value'] = value;
});
}
推荐阅读
- lxd - 通过 snap 安装 lxd 的权限被拒绝
- parse-server - 在解析服务器中以用户身份登录而无需使用主密钥的密码?
- html - 根据Angular中点击的img获取相关Pills内容
- python - 在 Python 中使用 Selenium,使用 xpath 查找元素进行网页抓取,.text
- python - 如何计算矩阵n次的行列式
- ag-grid - 在 agggrid 中写回值的函数/表达式
- python - Python 将生成器产量分成两部分
- mysql - SELECT @xi:=@xi+1 AS xc 是什么意思?
- lua - 如何让 Lua 垃圾收集器运行得更频繁?
- c# - 抽象、实体和属性注入与构造函数注入