首页 > 解决方案 > 从列表中获取 itemCount

问题描述

我有这个json结构

  "abc":{
        current_checklist:[
        {
         .... 
        },
        {
          "sections":[
              ...
           ]
        },
        {
             ...         
        }
     ]
  }

我想使用ListView,其中itemCount基于部分。我应该怎么写?

Widget _displayCheckList(ABCData abcData) {
    return ListView.builder(
      physics: NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      itemCount:
          abcData.abc.currentChecklist.???,length,  // how to get the "sections" length? 
      itemBuilder: (context, index) {
        return Text("Hello");
      },
    );
  }
}

标签: listflutterlistviewdart

解决方案


看到一些有效的示例 json 数据会很好。

您是否尝试过类似的方法:

abcData.abc.currentChecklist[0].sections or
abcData.abc.currentChecklist[1].sections

推荐阅读