mrg*_*t96 6 listview scroll position dart flutter
我目前有一个带有我AppBar
和我的页面内容的背景的堆栈。
我Container
在页面中央显示一个,与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'),
),
);
},
),
),
)
],
);
},
),
);
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当我有Positioned
小部件并且我已经明确命名了任何但不是所有的构造函数时,网格/列表视图不会滚动,即top:
, bottom:
, left:
, right:
。(我正在通过构建器懒惰地构建网格/列表视图)。
我有一个解决方法/hack,我可以在其中删除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)),
)
)
Run Code Online (Sandbox Code Playgroud)