screenToWorld method

Offset screenToWorld(
  1. Offset screenPoint
)

Converts a screen coordinate point to world coordinates.

Use this to transform mouse/touch positions or screen coordinates back to graph space, taking into account the current viewport position and zoom level.

Parameters:

  • screenPoint: The point in screen coordinates

Returns the corresponding point in world/graph coordinates.

Example:

final mousePos = event.localPosition; // Mouse position on screen
final graphPos = controller.screenToWorld(mousePos); // Position in graph

Implementation

Offset screenToWorld(Offset screenPoint) {
  final vp = _viewport.value;
  return Offset(
    (screenPoint.dx - vp.x) / vp.zoom,
    (screenPoint.dy - vp.y) / vp.zoom,
  );
}