ListView.builder显示任何内容



alertcardwidget是我写的小部件。我将其返回,但没有显示。这是我的代码:

       Flexible(
         child: Padding(
           child: SingleChildScrollView(
                  child: ListView.builder(
                        itemCount: state.data.length,
                        itemBuilder: (BuildContext context, int index) {
                    state.data["datas"].map<Widget>((f) {
                          return AlertCardWidget(
                            positionId: "${f["8020074"]}",
                            shipowner: "${f["8020076"]}",
                            customer: "${f["8020170"]}",
                            salesRepresenter: "${f["8020176"]}",
                            operationRepresenter: "${f["8020177"]}",
                            textContentFontColor:
                                AppTheme(Theme.of(context).brightness)
                                    .cardFontBackgroundColor,
                            textfont: Colors.redAccent,
                          );
                        }).toList();
                      },
                    ),
                  ),
                ),
              ),

没有显示错误。

我有我使用 ListView的项目。使用Listview代替ListView.builder的临界值是"垂直视口被给出了无限的高度错误"。当编写ListviewExpanded小部件的孩子时,问题已经解决。这是我的代码:

Expanded(
  child: Padding(
    padding: const EdgeInsets.all(4.0),
    child: ListView(
      children: state.data["datas"].map<Widget>((f) => AlertCardWidget(positionId: "${f["8020074"]}",
        shipowner: "${f["8020076"]}",
        customer: "${f["8020170"]}",
        salesRepresenter: "${f["8020176"]}",
        operationRepresenter: "${f["8020177"]}",
        textContentFontColor: AppTheme(Theme.of(context).brightness).cardFontBackgroundColor,
        textfont: Colors.redAccent,)).toList(),
    ),
  ),
),

也许是一个愚蠢的问题,但是为什么将列表映射到listView.builder中?您是否尝试过为每次迭代使用索引?因为我从该代码中了解的是,您所拥有的每个["datas"]项目都会像state.data.length一样多次生成整个列表。

也许尝试一下:

Flexible(
     child: Padding(
       child: SingleChildScrollView(
              child: ListView.builder(
                    itemCount: state.data.length,
                    itemBuilder: (BuildContext context, int index) {
                      return AlertCardWidget(
                        positionId: state.data[index]["datas"]["8020074"],
                        shipowner: state.data[index]["datas"]["8020076"],
                        customer: state.data[index]["datas"]["8020170"],
                        salesRepresenter: state.data[index]["datas"]["8020176"],
                        operationRepresenter: state.data[index]["datas"]["8020177"],
                        textContentFontColor:
                            AppTheme(Theme.of(context).brightness)
                                .cardFontBackgroundColor,
                        textfont: Colors.redAccent,
                      );
                  },
                ),
              ),
            ),
          ),

如果那不起作用,您是否介意向我们展示您要检索哪些数据?

您的itembuilder函数不返回值。

编辑:它应该返回列表中每个条目的单个小部件。这样的事情应该起作用。另外,填充小部件缺少填充属性。

   Flexible(
     child: Padding(
       child: SingleChildScrollView(
              child: ListView.builder(
                    itemCount: state.data.length,
                    itemBuilder: (BuildContext context, int index) {
                     final f  = state.data[index];
                      return AlertCardWidget(
                        positionId: "${f["8020074"]}",
                        shipowner: "${f["8020076"]}",
                        customer: "${f["8020170"]}",
                        salesRepresenter: "${f["8020176"]}",
                        operationRepresenter: "${f["8020177"]}",
                        textContentFontColor:
                            AppTheme(Theme.of(context).brightness)
                                .cardFontBackgroundColor,
                        textfont: Colors.redAccent,
                      );
                  },
                ),
              ),
            ),
          ),

最新更新