I was having a problem with my "tap position" being offset. I believe it was the same issue mentioned above. I was able to solve this similar problem by reading about keys and finding the location/size of widgets here:
https://medium.com/@diegoveloper/flutter-widget-size-and-position-b0a9ffed9407
So I didn't have to create another widget or layout builder as mentioned above, but I was able to just add a global key and then grab the position of the tap by doing the following with "currentContext" that comes from the key. Very cool!
void _handleLongPress(LongPressStartDetails details) {
final RenderBox referenceBox = _keyRink.currentContext.findRenderObject();
var x = referenceBox.globalToLocal(details.globalPosition);
if (x == tapPosition) {
Vibration.vibrate(duration: 50);
setState(() {
_shots[_homeShotCount] = tapPosition;
});
}
}
Here was my main scaffold where you can see the spot I added the key.
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: GestureDetector(
key: _keyRink,
onTapDown: _getTapPosition,
onLongPressStart: _handleLongPress,
child: Stack(
children: <Widget>[
AnimatedOpacity(
duration: Duration(milliseconds: 2500),
opacity: _rinkOpacity,
child: Center(
child: Image.asset('assets/rink.png',
width: size.width, height: size.height, fit: BoxFit.fill),
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Transform.rotate(
angle: animationRotate.value,
child: Transform.scale(
scale: animationDrop.value,
child: FlatButton(
onPressed: null,
padding: EdgeInsets.all(0.0),
child: Image.asset('assets/puck.png'))),
)
],
),
),
CustomPaint(
painter: ShapesPainter(),
child: FractionallySizedBox(heightFactor: 1.0,widthFactor: 1.0,),
),
],
),
),
drawer: Drawer(
child: drawerItems,
),
);
}