The localPosition property of DragUpdateDetails is different when a onTap callback is provided
Summary:
The localPosition property of the DragUpdateDetails object in the onPanUpdate callback is different when using a GestureDetector with an onTap callback compared to when using a GestureDetector without an onTap callback.
Steps to reproduce:
Create a Flutter app with the following code:
@override
Widget build(BuildContext context) {
return Column(children: [
GestureDetector(
onTap: () => print('look ma, im printing'),
onPanUpdate: (details) =>
print('red: ' + details.localPosition.dx.toString()),
child: Row(children: [
Container(width: 190, height: 100, color: Colors.red),
Container(width: 10, height: 100, color: Colors.redAccent),
]),
),
GestureDetector(
onPanUpdate: (details) =>
print('green: ' + details.localPosition.dx.toString()),
child: Row(children: [
Container(width: 190, height: 100, color: Colors.green),
Container(width: 10, height: 100, color: Colors.greenAccent),
]),
),
]);
}
}
Or use the following DartPad url: https://dartpad.dev/?id=290f20f2956e876aa9c246bc4dbccb41
Run the app on an emulator or physical device. Drag your finger across the red GestureDetector widget. Observe the output in the console. Drag your finger across the green GestureDetector widget. Observe the output in the console.
Expected behavior:
The localPosition values for the onPanUpdate callback for the red and green GestureDetector widgets should be the same.
Actual behavior:
The localPosition values for the onPanUpdate callback for the red and green GestureDetector widgets are different.
Hi @Bassiuz, I'm not sure you can get the same values with or without the onTap gesture present.
If you repeatedly drag your finger across the red area, do you get the same values?
Please also provide your flutter doctor -v output.
Thank you
Thanks for the response, in the meantime i figured out what the problem was. The gesture needs to resolve whether the user did a tap or a drag. So there is a delay until the drag gets recognized and thus it might be a different location.
In my solution i made sure save the starting point of the drag in the onTapDown event.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.