Flutter: Putting ListView.builder inside another ListView

No doubt ListView is one of the most used Container Widget in any Mobile Application as it gives us a seamless scrolling effect and a lot of space to put our content neatly. You are here because you might have received the following error:

Vertical viewport was given unbounded height.
The relevant error-causing widget was ListView

Your code might look like this:

ListView(
  children: [
    Container(
      child: ListView.builder(
        itemCount: snapshot.data.length,
        itemBuilder: (context, index) {}
      ),
    ),
  ]
)

Now add shrinkWrap: true, physics: ScrollPhysics(), to ListView.builder Widget and your issue will be resolved.

ListView.builder(
  shrinkWrap: true,
  physics: ScrollPhysics(),
  itemCount: snapshot.data.length,
  itemBuilder: (context, index) {}
),

Adding this will allow ListView Builder to maintain its finite height state without having an internal scrolling effect.

Solved.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.