【问题标题】:Rangeerror (index) : index out of range :index should be less than 30: 30Rangeerror (index) : index out of range :index 应该小于 30: 30
【发布时间】:2021-10-27 02:34:34
【问题描述】:

我正在使用 listView builder,它工作正常,但最后出现错误: Rangeerror (index) : index out of range :index 应该小于 30: 30。 以下是我的代码-

child: data != null
                    ? ListView.builder(itemBuilder: (context, index) {
                        return Container(
                          padding: const EdgeInsets.all(4.0),
                          decoration: BoxDecoration(
                              color: Colors.white10,
                              borderRadius: BorderRadius.circular(10),
                              boxShadow: [
                                BoxShadow(
                                    blurRadius: 15,
                                    offset: Offset(0, 0),
                                    color: Color(0x42000000).withOpacity(.08),
                                    spreadRadius: -10)
                              ]),
                          child: Padding(
                            padding: const EdgeInsets.all(4.0),
                            child: ListTile(
                              leading: Container(
                                width: 100,
                                child: Text(data["items"][index]["owner"]
                                    ["display_name"]),
                              ),
                              title: Text(data["items"][index]["title"]),
                              onTap: () {
                                Navigator.pop(context);
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => Answers(
                                            number: index,
                                          )),
                                );
                              },
                            ),
                          ),
                        );
                      })
                    : Center(
                        child: CircularProgressIndicator(),
                      ),
              ),
            )

【问题讨论】:

  • 我在这里找不到任何itemCount
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: android flutter dart flutter-layout flutter-listview


【解决方案1】:

您缺少itemCount 属性

添加到ListView.builder

itemCount: (data["items"] as List).lenght;

【讨论】:

    【解决方案2】:

    您能分享您的列表视图的完整代码吗? 对于您当前的代码, 尝试使用

    itemCount: data["items"].length
    

    【讨论】:

      猜你喜欢
      • 2013-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2021-03-25
      • 2021-12-27
      • 1970-01-01
      相关资源
      最近更新 更多