Home > Back-end >  Making parent adjust to size of child widget
Making parent adjust to size of child widget

Time:05-12

I am using a ListView Builder, and that has to be wrapped inside a Container. If i don't give a height parameter then i get Vertical viewport was given unbounded height. Now, because of this if i only have 1 item in the list, any content comes after the container, which wastes a lot of screen real estate and doesn't look aesthetically pleasing.

How can i make the parent widget i.e Container() to adjust to the size of child widget ListView.builder() ?

this is the image

CodePudding user response:

Add this shrinkWrap: true to your ListView and Remove Height from container.

snippet code:

return Container(
        child: ListView.builder(itemBuilder: (context, index) {
          return listItem(itemArray[index]),
        },
        itemCount: itemArray.length,
        shrinkWrap: true),
      );
  • Related