【发布时间】:2021-02-09 14:46:35
【问题描述】:
在此示例中,我尝试将我保存在列表中的值添加到 CheckboxListTile。 但由于某种原因,我被困在这里,我无法弄清楚如何解决这个问题。
全局列表
List<String> _lstNomeData = new List<String>();
价值观图
Map<String, bool> values = {
'$_lstNomeData[index]': false,
};
获取选中的复选框值
var tmpArray = [];
getCheckboxItems() {
values.forEach((key, value) {
if (value == true) {
tmpArray.add(key);
}
});
print(tmpArray);
tmpArray.clear();
}
身体
body: Column(
children: <Widget>[
Expanded(
child: ListView(
children: values.keys.map((String key) {
return new CheckboxListTile(
title: new Text(key),
value: values[key],
activeColor: Colors.blue,
checkColor: Colors.white,
onChanged: (bool value) {
setState(() {
values[key] = value;
});
},
);
}).toList(),
),
),
],
)
【问题讨论】:
标签: list flutter widget checkboxlist