简体   繁体   English

颤振:我如何将手势从 GestureDetector 传递给孩子?

[英]flutter: How I can pass gesture to children from GestureDetector?

I have the GestureDetector , and I detect only onHorizontalDrag if it started near the edges.我有GestureDetector ,如果它在边缘附近开始,我只检测onHorizontalDrag How I can pass the gesture to InteractiveViewer if the gesture is not valid for me?如果手势对我无效,我如何将手势传递给InteractiveViewer if(isHorizontalDragActive == false)

            return GestureDetector(
              behavior: HitTestBehavior.deferToChild,
              onHorizontalDragStart: (DragStartDetails details) {
                // allows start only near L/R edges.
                final double dX = details.localPosition.dx;
                final double dW = constraints.maxWidth / 6;
                if (dX < dW || dX > (constraints.maxWidth - dW)) {
                  isHorizontalDragActive = true;
                } else {
                  isHorizontalDragActive = false;
                }
              },
              onHorizontalDragEnd: (DragEndDetails details) {
                if (isHorizontalDragActive == true) {
                  final double velocity = details.primaryVelocity ?? 0;
                  if (velocity < 0) {
                    manager.toForwardPage();
                  } else if (velocity > 0) {
                    manager.toBackwardPage();
                  }
                }
                isHorizontalDragActive = false;
              },
              child: InteractiveViewer

Now if I scale InteractiveViewer I can't start moving content inside InteractiveViewer in a horizontal direction.现在,如果我缩放InteractiveViewer我将无法开始在水平方向上移动InteractiveViewer内的内容。

A GestureDetector wrapping the InteractiveViewer will not respond to GestureDetector events as expected.包装 InteractiveViewer 的 GestureDetector 不会按预期响应 GestureDetector 事件。 Try listeners尝试听众

  Listener(
    onPointerMove: (moveEvent){
       if(moveEvent.delta.dx > 0) {
           print("user swiped right");
       }
      }
      child: InteractiveViewer()
     .....
   )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 GestureDetector 中捕捉其孩子的手势? - How to catch gesture from its child in GestureDetector? 如何使用 svg 图像和 Flutter 的 GestureDetector 更改颜色? - How can I change color with GestureDetector of svg image and Flutter? Flutter:当我使用 iOS 向后滑动手势时,如何将数据传回 Navigator? - Flutter: How can I pass data back to Navigator when I use iOS swipe back gesture? Flutter 如何对这个手势检测器进行约束? - Flutter how do I give constraints to this gesturedetector? 如何检测 GestureDetector 是否悬停在 Flutter 中? - How do I detect if a GestureDetector is hovered in Flutter? 如何从 Flutter 中的 GestureDetector 中排除小部件 - How to exclude a widget from a GestureDetector in Flutter 如何在 Flutter/Dart 中将有状态的小部件子级之间的数据传递给他的父级 - How can I pass data between a statefulwidget children to his parent in Flutter/Dart 如何在 Flutter 中将点击传播到手势检测器的子节点? - How can I propagate taps to the child of a Gesture Detector in Flutter? 如何在 Flutter 中监听手势检测器的第二次点击? - How can I listen for second click in gesture detector in Flutter? Flutter)我想知道如何用 GestureDetector 检测手指的数量 - Flutter) I want to know how to detect the number of fingers with the GestureDetector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM