Reputation: 888
Is it possible to use GestureDetector — specifically the onTapUp gesture — inside of an InteractiveViewer?
I know InteractiveViewer uses a GestureDetector itself and overrides the onScaleEnd, onScaleStart, and onScaleUpdate methods to implement panning. However, onTapUp is not overriden, which makes me think there's potential to use it.
Upvotes: 6
Views: 2396
Reputation: 888
I did some digging around and found this in the InteractiveViewer's TransformationController documentation for the toScene() method:
Return the scene point at the given viewport point.
A viewport point is relative to the parent while a scene point is relative to the child, regardless of transformation. Calling toScene with a viewport point essentially returns the scene coordinate that lies underneath the viewport point given the transform.
The viewport transforms as the inverse of the child (i.e. moving the child left is equivalent to moving the viewport right).
This method is often useful when determining where an event on the parent occurs on the child. This example shows how to determine where a tap on the parent occurred on the child.
GestureDetector( onTapUp: (TapUpDetails details) { _childWasTappedAt = _transformationController.toScene( details.localPosition, ); }, child: InteractiveViewer( transformationController: _transformationController, child: child, ), ); }
So it seems that rather than having a GestureDetector as a child, the recommended solution is to wrap the InteractiveViewer with a GestureDetector, use a custom TransformationController, and get the position relative to the viewer viewport from this controller.
Upvotes: 7