detectTappedNode function

SankeyNode? detectTappedNode(
  1. List<SankeyNode> nodes,
  2. Offset tapPos
)

Determines if a tap hit a node and returns its id; returns null if no node is hit

nodes is the list of SankeyNode objects and tapPos is the Offset of the tap event in the canvas coordinate space

Implementation

SankeyNode? detectTappedNode(List<SankeyNode> nodes, Offset tapPos) {
  try {
    return nodes.firstWhere((node) => node.contains(tapPos));
  } on StateError {
    return null;
  }
}