addNode method

Future<bool?> addNode(
  1. ARNode node, {
  2. ARPlaneAnchor? planeAnchor,
})

Add given node to the given anchor of the underlying AR scene (or to its top-level if no anchor is given) and listen to any changes made to its transformation

Implementation

Future<bool?> addNode(ARNode node, {ARPlaneAnchor? planeAnchor}) async {
  try {
    node.transformNotifier.addListener(() {
      _channel.invokeMethod<void>('transformationChanged', {
        'name': node.name,
        'transformation':
            MatrixValueNotifierConverter().toJson(node.transformNotifier)
      });
    });
    if (planeAnchor != null) {
      planeAnchor.childNodes.add(node.name);
      return await _channel.invokeMethod<bool>('addNodeToPlaneAnchor',
          {'node': node.toMap(), 'anchor': planeAnchor.toJson()});
    } else {
      return await _channel.invokeMethod<bool>('addNode', node.toMap());
    }
  } on PlatformException catch (e) {
    return false;
  }
}