正如标题所说,在Flutter 动中使用堆栈时,如果"最后一个"渲染子对象与所有其他子对象重叠,则只能与该子对象交互.在我的应用程序中,我有一个ListWheelScrollView,它包含在一个Stack中,然后用位于ScrollView顶部的渐变"设置样式".

举个例子,这更有意义.

在这个几乎完全相同的情况下,存在一个问题:Flutter- GestureDetector not working with containers in stack

但是,它假定您使用的是手势检测器.

Stack(children: <Widget>[
          Container(
            height: 250,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: _style.fontSize * 1.5,
                  child: ListWheelScrollView.useDelegate(
                      controller: fixedExtentScrollController,
                      physics: FixedExtentScrollPhysics(),
                      itemExtent: _style.fontSize * 1.5,
                      childDelegate: ListWheelChildLoopingListDelegate(
                          children: hours
                              .map((hour) => hour < 10
                                  ? Text(
                                      "0$hour",
                                      style: _style,
                                    )
                                  : Text(
                                      "$hour",
                                      style: _style,
                                    ))
                              .toList())),
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      ":",
                      style: _style,
                    ),
                    SizedBox(
                      height: 25,
                    )
                  ],
                ),
                Container(
                  width: _style.fontSize * 1.5,
                  child: ListWheelScrollView.useDelegate(
                      physics: FixedExtentScrollPhysics(),
                      itemExtent: _style.fontSize * 1.5,
                      childDelegate: ListWheelChildLoopingListDelegate(
                          children: minutes
                              .map((minute) => minute < 10
                                  ? Text(
                                      "0$minute",
                                      style: _style,
                                    )
                                  : Text(
                                      "$minute",
                                      style: _style,
                                    ))
                              .toList())),
                ),
              ],
            ),
          ),
          Container(
                height: 250,
                child: Column(
                  children: <Widget>[
                    Container(
                      height: 75.3,
                      decoration: BoxDecoration(
                          gradient: LinearGradient(
                              begin: Alignment.bottomCenter,
                              end: Alignment.topCenter,
                              colors: [
                            Colors.white.withOpacity(0.1),
                            Theme.of(context).scaffoldBackgroundColor
                          ])),
                    ),
                    Center(
                        child: Container(
                            height: 83.3,
                            width: 220,
                            decoration: BoxDecoration(
                              border: Border.all(
                                  color: Color(0xFFc0ccd4), width: 5),
                            ))),
                  ],
                ),
          )
        ]),

设计和预期的一样完美,但是我不能再滚动了,因为容器在滚动小部件的顶部.

有解决办法吗?

推荐答案

您只需要包装所有不应该在IgnorePointer widgets中接收点击事件的小部件.
comments 中说你应该使用AbsorbPointer,然而,你不想在忽略的小部件上捕捉点击事件.

在您的示例中,您希望将上部、上部和堆栈顶部一样包装在IgnorePointer小部件中,即Container:

Stack(
  children: <Widget>[
    Container(...),
    IgnorePointer(
      child: Container(...),
    ),
  ],
)

Learn more美元.

Dart相关问答推荐

dart 日期时差(分钟)

DART列表由以奇怪方式链接的列表(即二维数组)组成

Flutter Getx - 未找到Xxx.您需要调用Get.put(Xxx()) - 但我已调用 Get.put(Xxx())

在 Column Flutter 中居中展开 ListView

从 PopupMenuItem 中删除填充(overflow menu)

在Flutter中实现像Chanel app一样的自定义滚动?

我可以动态应用 Dart 的字符串插值吗?

dart:js 和 js 包有什么区别?

Dart 中使用 ifAbsent 的 Map Update 方法

LinearProgressIndicator Flutter使用

每次我按下导航项时,底部的导航栏都会重新加载所有小部件

将Dart嵌入到应用程序中

如何从类中访问元数据注释?

Flutter判断变量是否为 NaN

如何在 Dart 2 中clone复杂对象

错误:default constructor is already defined

Dart 中使用的const关键字是什么?

Dart:如何判断变量类型是否为字符串

是否有任何官方计划在 Google App Engine 上支持 Dart?

我应该更喜欢迭代 Map.entries 还是 Map.values?