[英]ListView not scrolling in positioned Widget
我目前有一個堆棧,其中包含我的AppBar
和頁面內容的背景。
我在頁面中央顯示一個Container
,使用Positioned
小部件Positioned
,其中包含一個網格/列表視圖。
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: VehicleScreenAppBar(
title: title,
context: context,
),
body: LayoutBuilder(
builder: (contxt, vehicleListConstraints) {
return Stack(
overflow: Overflow.visible,
children: <Widget>[
AppBarBackDrop(constraints: vehicleListConstraints),
Positioned(
top: vehicleListConstraints.maxHeight * .15,
left: (vehicleListConstraints.maxWidth - vehicleListConstraints.maxWidth * .9) / 2,
child: Container(
color: Colors.red,
height: vehicleListConstraints.maxHeight * .6,
width: vehicleListConstraints.maxWidth * .9,
child: ListView.builder(
itemCount: 20,
itemBuilder: (context, i) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 50,
color: Colors.blue,
child: Text('text'),
),
);
},
),
),
)
],
);
},
),
);
}
我遇到的問題是,當我Positioned
小部件並且我已經明確命名了任何但不是所有的構造函數時,網格/列表視圖不會滾動,即top:
, bottom:
, left:
, right:
。 (我正在通過構建器懶惰地構建網格/列表視圖)。
我有一個解決方法/黑客,我刪除了Positioned
並將其替換為PageView
。 然后PageView
有一個children: <Widget> [ Container() ]
然后我通過邊距構造函數的top:
和left:
。
這現在可以使用,但不是我想為生產實現的東西。 如何讓網格/列表視圖在Positioned
小部件內滾動而不命名其所有構造函數?
對於包裹在定位小部件內的可滾動小部件,您應該給定位小部件的所有參數(左、右、上、下)一個值,然后它就會起作用。
Positioned(
top: 20.0,
left: 20.0,
right:0.0,
bottom:0.0
child: SizedBox(
//what ever code is)),
)
)
這將在頁面中央顯示Container
Positioned( top: 0.0, left: 0.0, right: 0.0, bottom: 0.0, child: //your code )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.