繁体   English   中英

ListView 不在定位的小部件中滚动

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM