createHitTestPath method
Path
createHitTestPath(
- Path originalPath,
- double tolerance, {
- ConnectionPathParameters? pathParams,
override
Creates an expanded path for hit testing The base implementation provides a simple stroke-based expansion
pathParams - Optional parameters used to create the original path.
Some connection styles can use these to create more optimized hit test paths.
Implementation
@override
Path createHitTestPath(
Path originalPath,
double tolerance, {
ConnectionPathParameters? pathParams,
}) {
if (pathParams == null) {
return Path()..addRect(originalPath.getBounds().inflate(tolerance));
}
// Calculate waypoints: [start, startExtension, endExtension, end]
final sourcePosition =
pathParams.sourcePort?.position ?? PortPosition.right;
final targetPosition = pathParams.targetPort?.position ?? PortPosition.left;
final startExtension = _calculateExtensionPoint(
pathParams.start,
sourcePosition,
pathParams.offset,
);
final endExtension = _calculateExtensionPoint(
pathParams.end,
targetPosition,
pathParams.offset,
);
// If extension is too small, skip it and create single rectangle
if (pathParams.offset < 5.0) {
return _createPreciseHitArea(pathParams.start, pathParams.end, tolerance);
}
// Create 3 rectangles: port→ext, ext→ext, ext→port
final combinedPath = Path();
combinedPath.addPath(
_createPreciseHitArea(pathParams.start, startExtension, tolerance),
Offset.zero,
);
combinedPath.addPath(
_createPreciseHitArea(startExtension, endExtension, tolerance),
Offset.zero,
);
combinedPath.addPath(
_createPreciseHitArea(endExtension, pathParams.end, tolerance),
Offset.zero,
);
return combinedPath;
}