【发布时间】:2021-03-04 12:17:24
【问题描述】:
我正在遍历 ListView.builder 中的列表项
List _rBoxes = new List();//declare
我要循环的数据是这样的:
{
"box_content": {
"box_1": [
{
"id": "9",
"name": "abc"
},
{
"id": "10",
"name": "xyz"
}
],
"box_2": [
{
"id": "8",
"name": "acc"
}
],
"box_3": [
{
"id": "1",
"name": "abc"
}
],
"box_4": [
{
"id": "4",
"name": "amno"
},
{
"id": "6",
"name": "jkl"
}
],
"box_5": [
{
"id": "7",
"name": "xre"
}
]
}
}
然后我将这些项目添加到列表中
_rBoxes.addAll(data['box_content']);//it gives error - Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>'
//小部件设计
ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: _rBoxItems.length,
itemBuilder: (BuildContext context, int index) {
return Text("${_rBoxItems[index]}",
style: TextStyle(fontSize: 20.0));
})
错误:
//这里我想在列表视图中循环box_1索引(仅),如果我给了如何实现这个
_rBoxItems['box_1'].length 会发生错误。实际上我陷入了这种情况,请帮我解决这个问题。
【问题讨论】:
-
_rBoxes.addAll(data['box_content']);你想全部添加到rBoxes吗?
标签: flutter dart flutter-layout