Rangeerror (index) : index out of range :index 应该小于 30: 30

Rangeerror (index) : index out of range :index should be less than 30: 30

我正在使用 listView 生成器,它工作正常,但最后出现错误:Rangeerror (index) : index out of range :index should be less than 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: data["items"].length

你不见了itemCount属性

将其添加到 ListView.builder

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