Flutter ListView.builder() is loading all items at once

Viewed 20

I have a ListView I'm initializing with ListView.builder() and it seems to be loading all items at once. This is the code:

ListView.builder(
  physics: NeverScrollableScrollPhysics(),
  shrinkWrap: true,
  itemBuilder: (context, index) {
    if (index == length) {
      Future.delayed(Duration(seconds: 2)).then((value) {
        setState(() => length += 10);
      });
      return Center(child: CircularProgressIndicator());
    }

    return Container(
      color: Colors.red,
      padding: EdgeInsets.all(24.0),
      margin: EdgeInsets.all(12.0),
      child: Text(index.toString()),
    );
  },
  itemCount: length + 1,
)

This ListView is wrapped in another ListView. I'm trying to make a network call to load more items once I hit the bottom of the list, but it just gets called over and over again even when I haven't scrolled to the bottom. Is this because I have it nested in a second ListView?

0 Answers
Related