getPortCenter method
Gets the visual center of a port in graph coordinates.
This is the center of the port widget, used for hit testing bounds and visual highlighting.
Parameters:
portId- The unique identifier of the portportSize- The size of the port widget (width x height)shape- Optional shape to use for port position calculation
Returns the absolute Offset of the port's visual center in graph coordinates.
Throws ArgumentError if no port with the given portId is found.
See also:
- getVisualPortOrigin for the port widget's top-left position
- getConnectionPoint for the connection attachment position
Implementation
Offset getPortCenter(
String portId, {
required Size portSize,
NodeShape? shape,
}) {
final port = [
...inputPorts,
...outputPorts,
].cast<Port?>().firstWhere((p) => p?.id == portId, orElse: () => null);
if (port == null) {
throw ArgumentError('Port $portId not found');
}
// Center offset is simply half the port size (doesn't depend on port position)
final centerOffset = Offset(portSize.width / 2, portSize.height / 2);
// Convert from node coordinates to absolute graph coordinates
return visualPosition.value +
getVisualPortOrigin(portId, portSize: portSize, shape: shape) +
centerOffset;
}