我需要在Column内使用ListView.builder,但要在Column内使用它,我不仅需要设置高度,还需要用Container包装它,在这里我使用MediaQuery.of(context).size.height,并且可以正常工作,但有一个问题,它表明RenderFlex在底部溢出226个像素。如何避免它?
Column(
children: <Widget>[
getTopWidget(),
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: ListView.builder(
itemCount: shapShot.data.length,
itemBuilder: (context,index){
return EventCard(
title: shapShot.data[index].title,
details: shapShot.data[index].details,
imageUrl: shapShot.data[index].imageUrl,
);
}),
),
],
);
我尝试过Flexible,但没有用
由于topWidget()而发生,您所能做的就是用Expanded包装内部容器,并删除所给的高度。展开的小部件将使容器占用可用的完整空间。
Column(
children: <Widget>[
getTopWidget(),
//Wrap the container below with expanded
Container(
// remove this height
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: ListView.builder(
itemCount: shapShot.data.length,
itemBuilder: (context,index){
return EventCard(
title: shapShot.data[index].title,
details: shapShot.data[index].details,
imageUrl: shapShot.data[index].imageUrl,
);
}),
),
],
);
您可以这样使用它:
Column(
children: <Widget>[
getTopWidget(),
Expanded(
child: ListView.builder(
itemCount: shapShot.data.length,
itemBuilder: (context,index){
return EventCard(
title: shapShot.data[index].title,
details: shapShot.data[index].details,
imageUrl: shapShot.data[index].imageUrl,
);
}),
),
],
);
因为如果使用MediaQuery.of(context).size.height,它将溢出视图。如已显示在应用程序上。