首页 > 解决方案 > 使堆栈背景中的 ListView 可滚动

问题描述

我有一个 Stack,它的最底部有一些容器和水平 listView。(有意地,它是设计的一部分)。现在我试图滚动浏览它,它不起作用,因为顶部容器使它无法访问。如何保持相同的小部件树但使底部 listView 可滚动?

return Stack(
    children: <Widget>[
      AnimatedBuilder(
                animation: ctrl,
        builder: (context, child){
          var pos = ctrl.position.pixels;
          return Container(
          height: pos<h?(pos/h * 250):250,
          child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemBuilder: (ctxt, index){
              return Container(
                height: pos<h?(pos/h * 250):250,
                width: 250,
                child: Image(), //Horizontal listview
              );
            },
          ),
          );
        },
        ),
      ListView(
        controller: ctrl,
        children: <Widget>[
          AnimatedBuilder(
            animation: ctrl,
            builder: (context, child){
              var pos = ctrl.position.pixels;
              return Container(
                height: pos<h?(pos/h * 250):250,
              );
            },
          ),
          //This is the container I'm talking about, it's just like padding(It's nothing in there)
        ],
      ),
    ],
  );

标签: flutterflutter-layout

解决方案


您可以将ListView后面的Container顺序放在 里面Stack,这样它就会结束Container并且您可以与它进行交互。

或者您可以将 with 包裹Container起来IgnorePointer,这样手势就不会被 拦截,Container您可以与 . 进行交互ListView


推荐阅读