Flutter:显示嵌套 JSON 数据中的指定行

Flutter : show specified row from nested JSON data

我有这样的未来列表的未来构建器,我想查看预测对象为空的数据:

[
  {
    "id": 1,
    "home": "Turkey",
    "away": "Italy",
    "h_goals": 0,
    "a_goals": 0,
    "date": "2021-02-06",
    "time": "22:00",
    "predect": [
      {
        "id": 3,
        "user_id": 10,
        "match_id": 1,
        "h_predect": 1,
        "a_predect": 1,
        "player_id": 1,
        "point": 0,
        "username": "sar"
      }
    ]
  },
  {
    "id": 2,
    "home": "Denmark",
    "away": "Finland",
    "h_goals": 0,
    "a_goals": 0,
    "date": "2021-06-12",
    "time": "19:00",
    "predect": []
  },
]

我想显示预测为空的匹配详细信息,我有这个小部件但无法使用:

return FutureBuilder(
            future: mathesProv.matchsWithUserPredects(username, token),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return ListView.builder(
                    itemCount: snapshot.data.length,
                    itemBuilder: (context, index) {
                      var item = snapshot.data[index];
                      if (item.predect == null) {
                        return Text('${item.home}');
                      } else {
                        return Container(
                          child: Text('$index'),
                        );
                      }
                    });
              } else {
                return Text('loading');
              }
            });

如何查看预测列表为空的行?

您忘记为长度 = 0 添加检查

    return FutureBuilder(
        future: mathesProv.matchsWithUserPredects(username, token),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (context, index) {
                  var item = snapshot.data[index];
                  if ((item.predect == null)||(item.predect.length==0)) {
                    return Text('${item.home}');
                  } else {
                    return Container(
                      child: Text('$index'),
                    );
                  }
                });
          } else {
            return Text('loading');
          }
        });