[英]CheckBoxListTile Flutter Single Choice Selection
我尝试在 Flutter 中使用 JSON 解析方法从 RESTAPI 链接获取数据。 我使小部件能够检查复选框,但它检查了所有而不是Single Choice ,我尝试了多种方法,但仍然无法正确。 这是我的以下代码
ListView.builder(
shrinkWrap: true,
cacheExtent: 34,
primary: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return CheckboxListTile(
activeColor: Const.msinAccent,
title:
Text(snapshot.data[index].name.toString().toUpperCase()),
value: _isChecked,
secondary: CircleAvatar(
backgroundImage:
NetworkImage(snapshot.data[index].pic, scale: 13.3),
),
onChanged: (bool val) {
setState(() {
this._isChecked = val;
});
},
tristate: true,
);
},
);
我是否做错了什么或错过了什么?
没关系,我找到了解决方案。
Set selectedsubs = Set();
ListView.builder(
shrinkWrap: true,
cacheExtent: 34,
primary: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return CheckboxListTile(
activeColor: Const.msinAccent,
title:
Text(snapshot.data[index].name.toString().toUpperCase()),
value: selectedsubs.contains(snapshot.data[index].name),
secondary: CircleAvatar(
backgroundImage:
NetworkImage(snapshot.data[index].pic, scale: 13.3),
),
onChanged: (bool val) {
setState(() {
this._isChecked = val;
selectedsubs.add(snapshot.data[index].name);
});
},
tristate: true,
);
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.