1

I'm using listView builder and it's working fine but giving an ERROR AT THE LAST : Rangeerror (index) : index out of range :index should be less than 30: 30. The following is my code -

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(),
                      ),
              ),
            )

2 Answers2

3

You're missing itemCount property

  • Add it to ListView.builder
itemCount: (data["items"] as List).length;
Nagual
  • 1,576
  • 10
  • 17
  • 27
0

Could you share your full code of your listview? For your current code, Try to use

itemCount: data["items"].length
Kin Cheng
  • 88
  • 5