hitTestAtScreenPosition method

Future<ARHitTestResult?> hitTestAtScreenPosition(
  1. double x,
  2. double y
)

Hit-tests an arbitrary screen position (device pixels) against the current AR frame and returns the closest usable hit, or null if nothing trackable is under that point.

Unlike onPlaneOrPointTap this does not require a user tap, so it can drive a crosshair/reticle that continuously reports what it is aimed at.

Implementation

Future<ARHitTestResult?> hitTestAtScreenPosition(double x, double y) async {
  try {
    final result = await _channel
        .invokeMethod<Map<dynamic, dynamic>>('hitTestAtScreenPosition', {
      'x': x,
      'y': y,
    });
    if (result == null) return null;
    return ARHitTestResult.fromJson(Map<String, dynamic>.from(result));
  } catch (e) {
    if (debug) {
      print('hitTestAtScreenPosition failed: $e');
    }
    return null;
  }
}