I assume you're using something like this to get the local position:
RenderBox getBox = context.findRenderObject();
var local = getBox.globalToLocal(start.globalPosition);
The reason you'd be getting the wrong offset after doing that has to do with the context
you're using to find the local position.
If you're using the overall widget's context, essentially what you're doing is calculating the offset within the overall widget. i.e.
YourWidget <-- context
Center
Container
GestureDetector
...
Let's say that the screen looks something like this:
1__________________________
| | <--- YourWidget
| 2_________ |
| | gesture | |
| | detector| |
| | 3. | |
| |_________| |
| |
|__________________________|
With 1 being the top left of your overall widget (and the screen), 2 being the top left of your gesture detector, and 3 being the point where you tap.
By using the context of YourWidget, you're calculating the position of the tap based on the difference between 1 and 3. If 1 happens to be at the top left of the screen, the result will match the global coordinates.
By using the context for your gesture detector, you'd instead be measuring the distance between 2 and 3, which will give you the offset you want.
There's two ways to fix this - either you can wrap your GestureDetector in a Builder widget, or you can create a new Stateful/Stateless widget that encapsulates just the GestureDetector. I'd personally recommend creating a new widget.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…