Is there a better way to check Left/Right Drag in #flutter. I have done it but somtime it works sometime it doesn't.
new GestureDetector(
onHorizontalDragEnd: (DragEndDetails details) {
print("Drag Left - AddValue");
setState((){
_value++;
});
if (details.velocity.pixelsPerSecond.dx > -1000.0) {
print("Drag Right - SubValue");
setState((){
_value--;
});
}
},
child: new Container(
child:new Text("$_value"),
),
);
using the GestureDetector widget and its panUpdate method, calculate the distance moved.
GestureDetector(
onPanStart: (DragStartDetails details) {
initial = details.globalPosition.dx;
},
onPanUpdate: (DragUpdateDetails details) {
distance= details.globalPosition.dx - initial;
},
onPanEnd: (DragEndDetails details) {
initial = 0.0;
print(distance);
//+ve distance signifies a drag from left to right(start to end)
//-ve distance signifies a drag from right to left(end to start)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With