get coordinates of touch in flutter code example
Example: get coordinates of touch in flutter
void onTapDown(BuildContext context, TapDownDetails details) {
print('${details.globalPosition}');
final RenderBox box = context.findRenderObject();
final Offset localOffset = box.globalToLocal(details.globalPosition);
setState(() {
posx = localOffset.dx;
posy = localOffset.dy;
});
_showPopupMenu();
}
_showPopupMenu() {
showMenu<String>(
context: context,
position: RelativeRect.fromLTRB(0.0, posy, 0.0,
0.0),
items: [
PopupMenuItem<String>(
child: Text(
'Edit Details',
style: Theme.of(context).textTheme.caption,
),
value: '1'),
PopupMenuItem<String>(
child: Text(
'Add/Edit Photo',
style: Theme.of(context).textTheme.caption,
),
value: '2'),
PopupMenuItem<String>(
child: Text(
'Add/Edit QR code',
style: Theme.of(context).textTheme.caption,
),
value: '3'),
],
elevation: 8.0,
).then<void>((String itemSelected) {
if (itemSelected == null) return;
if (itemSelected == "1") {
} else if (itemSelected == "2") {
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => UpdateMachineCode(),
),
);
}
});
}