Reputation: 392
I am trying to implement Match-The-Following. The approach I could come up with is that the onPanStart
and onPanEnd
to get the starting Offset
and ending Offset
. I also need to get the Offset of the widget on the screen to match.
Is there any method to get the local position of widget on the screen (Widget is a Container
) ?
Upvotes: 3
Views: 3778
Reputation: 1939
I think this is what you are looking for:
Set a key for the Widget:
Container(
key: _key,
color: Colors.red,
),
And get the position of the widget like this:
final RenderBox renderBox = _key.currentContext.findRenderObject();
final position = renderBox.localToGlobal(Offset.zero);
Upvotes: 3