【问题标题】:flutter: How I can pass gesture to children from GestureDetector?颤振:如何从 GestureDetector 向孩子传递手势?
【发布时间】:2021-12-28 00:37:37
【问题描述】:

我有GestureDetector,如果它在边缘附近开始,我只检测到onHorizontalDrag。如果手势对我无效,我如何将手势传递给InteractiveViewerif(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

现在,如果我缩放InteractiveViewer,我无法开始在InteractiveViewer 内水平方向移动内容。

【问题讨论】:

    标签: flutter uigesturerecognizer gesturedetector


    【解决方案1】:

    包装 InteractiveViewer 的 GestureDetector 不会按预期响应 GestureDetector 事件。试听者

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

    【讨论】:

      猜你喜欢
      • 2021-05-31
      • 2021-01-26
      • 2021-03-14
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多