Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node on tap not working? #221

Open
AlbaneseRemy opened this issue Nov 27, 2023 · 1 comment
Open

Node on tap not working? #221

AlbaneseRemy opened this issue Nov 27, 2023 · 1 comment

Comments

@AlbaneseRemy
Copy link

AlbaneseRemy commented Nov 27, 2023

Hello,

I'm adding nodes anchored to an image i'm tracking to my AR View.
But somehow, the on tap event is not triggering when clicking on the node. Please find my code at the end of the issue.

I don't have any error in my console but a line showing repetitively saying :

E/native (25852): E0000 00:00:1701099186.536445 25852 hit_test.cc:426] INTERNAL: No point hit.

Am I doing something wrong?

Thanks for your help

class _StopArCorePageState extends State<StopArCorePage> {
  ArCoreController? arCoreController;
  Map<int, ArCoreAugmentedImage> augmentedImagesMap = {};

  @override
  Widget build(BuildContext context) {
    return ArCoreView(
      onArCoreViewCreated: _onArCoreViewCreated,
      type: ArCoreViewType.AUGMENTEDIMAGES,
      enableTapRecognizer: true,
      enableUpdateListener: true,
    );
  }

  void _onArCoreViewCreated(ArCoreController controller) {
    arCoreController = controller;
    arCoreController!.onTrackingImage = _handleOnTrackingImage;
    arCoreController!.onNodeTap = _handleOnNodeTap;
    loadImageTrackers();
  }

 Future<void> loadImageTrackers() async {
    Map<String, Uint8List> bytesMap = {};
    for (final image in widget.data.imageAssets) {
      if (image.uri != null && image.uri!.isNotEmpty) {
        final response = await http.get(Uri.parse(image.uri!));
        if (response.statusCode == 200) {
          final ByteData bytes = ByteData.sublistView(Uint8List.fromList(response.bodyBytes));
          bytesMap[image.id] = bytes.buffer.asUint8List();
        }
      }
    }
    arCoreController?.loadMultipleAugmentedImage(bytesMap: bytesMap);
  }

  void _handleOnTrackingImage(ArCoreAugmentedImage augmentedImage) {
    if (!augmentedImagesMap.containsKey(augmentedImage.index)) {
      augmentedImagesMap[augmentedImage.index] = augmentedImage;
      addImageNode(augmentedImage);
    }
  }

  void _handleOnNodeTap(String name) {
    print("Name of the node: $name");
    _showToast(name);
  }

  Future<void> addImageNode(ArCoreAugmentedImage augmentedImage) async{
    final ByteData flag = await rootBundle.load("images/target.png");
    final vector64.Vector4 rotationVector = vector64.Vector4(1, 0, 0, -pi / 4);
    final node = ArCoreNode(
      name: "node",
      image: ArCoreImage(
        bytes: flag.buffer.asUint8List(),
        width: flag.getUint32(16) ~/ 2,
        height: flag.getUint32(20) ~/ 2,
      ),
      rotation: rotationVector,
    );
    
    arCoreController?.addArCoreNodeToAugmentedImage(node, augmentedImage.index);
  }

  void _showToast(String name) {
    Fluttertoast.showToast(
        msg: "Clicked on node $name",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        textColor: Colors.white,
        fontSize: 16,
    );

  }

  @override
  void dispose() {
    arCoreController?.dispose();
    super.dispose();
  }
}
@AlbaneseRemy
Copy link
Author

Also, I don't know if that is linked, but when I leave my AR Page, I get this error:

E/flutter (25852): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null cannot be cast to non-null type android.view.View, null, java.lang.NullPointerException: null cannot be cast to non-null type android.view.View
E/flutter (25852): at com.difrancescogianmarco.arcore_flutter_plugin.BaseArCoreView.getView(BaseArCoreView.kt:88)
E/flutter (25852): at io.flutter.plugin.platform.VirtualDisplayController.getView(VirtualDisplayController.java:240)
E/flutter (25852): at io.flutter.plugin.platform.PlatformViewsController$1.dispose(PlatformViewsController.java:245)
E/flutter (25852): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.dispose(PlatformViewsChannel.java:150)
E/flutter (25852): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:58)
E/flutter (25852): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/flutter (25852): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (25852): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter (25852): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (25852): at android.os.Handler.handleCallback(Handler.java:942)
E/flutter (25852): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (25852): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter (25852): at android.os.Looper.loop(Looper.java:313)
E/flutter (25852): at android.app.ActivityThread.main(ActivityThread.java:8757)
E/flutter (25852): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (25852): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/flutter (25852): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
E/flutter (25852): )
E/flutter (25852): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
E/flutter (25852): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
E/flutter (25852):
E/flutter (25852): #2 AndroidViewController.dispose (package:flutter/src/services/platform_views.dart:949:7)
E/flutter (25852):
E/flutter (25852):
E/BufferQueueProducer(25852): SurfaceTexture-0-25852-0 dequeueBuffer: BufferQueue has been abandoned
E/BufferQueueProducer(25852): SurfaceTexture-0-25852-0 dequeueBuffer: BufferQueue has been abandoned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant