XenseAR SDK Usage Guide
For detailed installation instructions of the XenseAR SDK for Flutter, refer to:
The XenseAR SDK is used as a widget in Flutter. Simply invoke EmbedUnity:
Widget build(BuildContext context) {
return Scaffold(
body: EmbedUnity(
onMessageFromUnity: (String message) {
// Receive message from Unity
},
),
);
}Bidirectional Communication Between Flutter and XenseAR SDK
1. Send Data from Flutter to XenseAR SDK
Flutter can use the built-in method to invoke any method exposed by XenseAR:
import 'package:flutter_embed_unity/flutter_embed_unity.dart';
sendToUnity(GameObjectName, MethodName, ParameterValue)2. Send Data from XenseAR SDK to Flutter Widget
The SDK can send data back to Flutter using a static method:
SendToFlutter.Send(StringData);Flutter receives and handles the callback directly at the widget initialization point:
import 'package:flutter_embed_unity/flutter_embed_unity.dart';
EmbedUnity(
onMessageFromUnity: (String message) {
// Receive message from Unity
},
);3. Pause and Resume SDK
The flutter_embed_unity package provides two methods to pause and resume the SDK:
import 'package:flutter_embed_unity/flutter_embed_unity.dart';
pauseUnity()
resumeUnity()Important
There is a known issue where the Android Native WebView does not automatically hide when the XenseAR widget is closed. When toggling the visibility of the XenseAR SDK:
// Before hiding EmbedUnity
sendToUnity("WebviewCanvas", "FlutterPause", "true");
WidgetsBinding.instance.addPostFrameCallback((_) {
pauseUnity(),
}),
// After showing EmbedUnity
resumeUnity(),
WidgetsBinding.instance.addPostFrameCallback((_) {
sendToUnity("WebviewCanvas", "FlutterPause", "false");
}),Last updated on