[英]Flutter ListView.Builder() in scrollable Column with other widgets
[英]Flutter - ListView.builder renders widgets but not scrollable
我的 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('');
}
},
),
);
},
),
);
}
这会呈现小部件,但没有溢出但它不是可滚动的。 在物理中使用AlwaysScrollableScrollPhysics
、 NeverScrollableScrollPhysics
、 ScrollPhysics
也不起作用。 同样将 shrinkWrap 作为false
返回任何小部件。
列表视图认为它更大,因为您的容器没有固定高度。 尝试将容器的高度设置为MediaQuery.of(context).size.height
并且列表视图将知道它的边界。
当它的 shrinkWrap 为真时,它不会滚动。
尝试这个:
ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemExtent: 'sizeOfeachElement (ex:100)'
并删除Expanded
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.