I have a column that has 3 children. The third child has a ListView. How do I set the height of the ListView such that it does not overflow the screen. I do not want to calculate the height by subtracting the height of other 2 children from the screen height. I tried LayoutBuilder but the box constraint I get has Infinity as max height (BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity) )
My widget tree looks something like this
Container( //Container A
height: MediaQuery.of(context).size.height,
child:Column(children:[
TitleWidget(),
SubtitleWidget(),
Container( //Container B
child:ListView(children:getChildren())
)
])
)
The height of the Container A is the screen height. But height of Container B should be Screen height - height of TitleWidget() - height of SubtitleWidget(). If i don't set the height of container B explicitly, I am getting "A RenderFlex overflowed by X pixels on the bottom".
Am I missing something really obvious here?
thanks
2 Answers 2
Wrap you list view with Expanded widget instead of Container widget.
Comments
I had a Similar Issue. In my case, I kept the Container and in my ListView I added shrinkWrap: true, this will shrink the size of the ListView to the total height of all it's children.
And physics: NeverScrollableScrollPhysics(), I Specifically don't want the ListView to scroll under the column items, but I want everything to scroll together.