Flutter- GestureDetector检测水平和垂直拖动的方向 [英] Flutter- GestureDetector detect the direction of Horizontal and Vertical Drag

查看:160
本文介绍了Flutter- GestureDetector检测水平和垂直拖动的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GestureDetector,但是没有找到任何告诉您拖动方向的onXYZ事件.

I am using GestureDetector and didn't find any onXYZ event which tells you the direction of drag.

推荐答案

您尝试过onPanUpdate(details)方法吗?这是您的操作方法.

Did you try onPanUpdate(details) method? Here is how you can do it.

GestureDetector(onPanUpdate: (details) {
  if (details.delta.dx > 0)
    print("Dragging in +X direction");
  else
    print("Dragging in -X direction");

  if (details.delta.dy > 0)
    print("Dragging in +Y direction");
  else
    print("Dragging in -Y direction");
});

注意:如果按anmol.majhail所述设置onHorizontalDragUpdate()onVerticalDragUpdate(),则此回调会导致崩溃.

Note: This callback causes a crash if onHorizontalDragUpdate() or onVerticalDragUpdate() is set as mentioned by anmol.majhail.

这篇关于Flutter- GestureDetector检测水平和垂直拖动的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆