本文介绍了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");
},
child: Container(
color: Colors.blue,
width: double.infinity,
height: double.infinity,
),
)
注意:如果 onHorizontalDragUpdate()
或 onVerticalDragUpdate()
也如 anmol.majhail 所述提供,则此回调会导致崩溃.
Note: This callback causes a crash if onHorizontalDragUpdate()
or onVerticalDragUpdate()
is also provided as mentioned by anmol.majhail.
这篇关于Flutter- GestureDetector 检测水平和垂直拖动的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!