将futureBuilder中的数据插入表中

时间:2019-07-12 07:22:53

标签: flutter flutter-web

我想将从futureBuilder获得的数据显示到表中,这是我尝试的代码,但是当我运行浏览时,会出现如下错误

         FutureBuilder(
      future: UserController.getActivity(_selectedUser),
      builder: (context, snapshot) {
        if (snapshot.hasData != null) {
          return ListView.builder(
            itemCount: snapshot.data.length,
            itemBuilder: (context, position){
              var item = snapshot.data.elementAt(position);
              return Container(
            child: Table(
                children: List<TableRow>.generate(10, (i) {
                  return TableRow(
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  width: 0.5, color: Colors.grey))),
                      children: [
                        Container(
                          padding: EdgeInsets.all(18),
                          child: Text(
                            //data[i].author.toString(),
                            "${item["activity"]["project"]}",
                            style: TextStyle(
                              fontSize: 14,
                              color: Colors.black,
                            ),
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.all(18),
                          child: Text(
                            //data[i].stars.toString(),
                            item["created_at"],
                            style: TextStyle(
                              fontSize: 14,
                              color: Colors.black,
                            ),
                          ),
                        )
                      ]);
                })),
          );

            }
          );

        }
      },
    ),

如果我在显示数据时使用listView,由于数据很多,它将变得无效

1 个答案:

答案 0 :(得分:0)

此行错误

  

itemCount:snapshot.data.length,

在快照中找不到

length。您需要检查未来UserController的返回类型。

要验证代码是否运行正常,可以设置默认值

只需验证用户界面工作正常

  

itemCount:10

之后,您需要检查退货类型。