[英]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.