[英]Flutter - ListView.builder renders widgets but not scrollable
I have my ListView.builder inside Expanded widget which render widgets correctly on the screen but I cannot scroll the widgets rendered by it.我的 ListView.builder 在 Expanded 小部件内,它可以在屏幕上正确呈现小部件,但我无法滚动它呈现的小部件。
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: getPostsForUid(),
builder: (_, snap) {
return Expanded(
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: snap.data.length,
itemBuilder: (_, index) {
if (snap.data[index]['post_type'] == 'real_estate') {
return realEstate(snap, index);
}
else if (snap.data[index]['post_type'] == 'video_sharing') {
return videoSharing(snap, index);
}
else {
return Text('');
}
},
),
);
},
),
);
}
This renders widgets but there is no overflow but its not Scrollable.这会呈现小部件,但没有溢出但它不是可滚动的。 Using AlwaysScrollableScrollPhysics
, NeverScrollableScrollPhysics
, ScrollPhysics
in physics doesn't work either.在物理中使用AlwaysScrollableScrollPhysics
、 NeverScrollableScrollPhysics
、 ScrollPhysics
也不起作用。 Also tring shrinkWrap as false
returns no widgets whatsoever.同样将 shrinkWrap 作为false
返回任何小部件。
The list view thinks it's bigger, because your container has no fixed height.列表视图认为它更大,因为您的容器没有固定高度。 Try setting the height of the container to MediaQuery.of(context).size.height
and the list view will know its bounds.尝试将容器的高度设置为MediaQuery.of(context).size.height
并且列表视图将知道它的边界。
it will not scroll while it's shrinkWrap is true.当它的 shrinkWrap 为真时,它不会滚动。
try this:尝试这个:
ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemExtent: 'sizeOfeachElement (ex:100)'
and remove Expanded
并删除Expanded
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.