Flutter 在listView颤振中显示复选框
请帮忙! 表行中有两个复选框。第一个复选框可单击,但第二个复选框不可单击Flutter 在listView颤振中显示复选框,flutter,dart,checkbox,Flutter,Dart,Checkbox,请帮忙! 表行中有两个复选框。第一个复选框可单击,但第二个复选框不可单击 ListView.builder( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), itemCount: widget.checklist['sections'].length, i
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.checklist['sections'].length,
itemBuilder: (context, index) {
final item = widget.checklist['sections'][index];
String s = item['applicable'];
var a = s.split(",");
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Table(
columnWidths: {
0: FixedColumnWidth(
250.0), // fixed to 100 width
1: FlexColumnWidth(),
2: FlexColumnWidth(), //fixed to 100 width
},
defaultColumnWidth: FixedColumnWidth(120),
border: TableBorder.all(),
children: [
TableRow(children: [
TableCell(
child: Container(
color: Colors.grey.shade300,
child: Padding(
padding: EdgeInsets.all(10),
child: Text(item['name'])))),
for (var i in a)
TableCell(
child: Container(
color: Colors.grey.shade300,
child: Padding(
padding: EdgeInsets.all(10),
child: Text(i))))
]),
...item['questions']
.asMap()
.entries
.map((items) {
print(items.key);
return TableRow(children: [
Padding(
padding: EdgeInsets.all(10),
child: Text(items.value['name'])),
Checkbox(
tristate: true,
value: true,
onChanged: (bool value) {
setState(() {
widget.checklist['sections']
[items.keys] = value;
});
},
),
Checkbox(onChanged: null, value: false)
]);
}).toList()
])
]);
// );
})
但是我得到了这个错误
'package:flutter/src/material/checkbox.dart': Failed assertion: line 76 pos 15: 'tristate || value != null': is not true.
请从Flatter本身尝试此CheckboxListTile
基于您的错误,该错误表明
三态
不是真的(这是正确的,因为它默认为假,您没有自己设置它)或值==null
(这里很可能是这种情况)
您的复选框
实现将其用作值:
复选框(
值:值[items.key],
...
),
您的值
映射没有一个项。键
作为键。我建议您调试此部分,或者实际将tristate
设置为true
,并查看您的复选框是否确实具有额外状态(将在框中显示为“-”)
从这里,您可能会发现哪个键不是
值的一部分映射 如何将tristate设置为true?这也是复选框本身的一个属性!只需使用复选框(三态:true,…)进行后期更新。现在我可以看到所有复选框都已选中。如何根据它们的索引进行检查?现在您已经设置了value:true
,您希望将其保持在value:values[items.key]
,因为现在tristate为true时,您将看到哪些值为null,因为在复选框中,所有为null的值都显示为“-”,我的值声明如下List values=List()代码>