【发布时间】:2019-08-20 10:33:06
【问题描述】:
在我的这部分代码中,当我勾选 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}");
}
}
希望分别选择列表的每个元素。
【问题讨论】:
标签: android flutter dart checkboxlist