Search code examples
dartdart-html

Dart: onContextMenu position misplaced


I have a problem with mouse right click menu. My web app has left navigation div, toolbar div, and contentView div. contentView div shows all of my contents /works kind of like web within web/. So here the problem begins. I created onContextMenu on my table like this:

tr.onContextMenu.listen((e) {
   contextMenu.style.display = 'block';
   contextMenu.style.left = "${e.page.x}px";
   contextMenu.style.top = "${e.page.y}px";
   selectedRow.clear();
   selectedRow.add(tr);
}); 

When i click right button it takes the position from whole window but when it shows the context menu, the position is based on contentView div. For example if my mouse position is (200,200) it's like (wholepage.0+200,wholepage.0+300) and context menu position would be around (400,500) which is like (contentView div.0+200,contentView div.0+300). So how can i show my context menu at where mouse is clicked?


Solution

  • Well i just changed ${e.page.x}px; ${e.page.y}px; to ${e.layer.x}px; ${e.layer.y}px; and now it works.