Android XR + Flutter: Building Cross-Platform Smart Glasses Experiences
Introduction
Flutter can provide a shared application layer while Kotlin handles Android XR functionality.
Flutter
|
MethodChannel
|
Kotlin
|
Android XR
|
Smart Glasses
1. Create the Flutter channel
static const channel = MethodChannel('xr/device');
Future<bool> isAvailable() async {
return await channel.invokeMethod('isAvailable') ?? false;
}
2. Implement Kotlin
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
"xr/device"
).setMethodCallHandler { call, result ->
when (call.method) {
"isAvailable" -> result.success(true)
else -> result.notImplemented()
}
}
3. Create a service layer
class XrService {
Future<bool> available() => XrBridge.isAvailable();
}
Do not put platform calls directly inside widgets.
4. Stream device events
For continuous events, use an EventChannel rather than repeatedly polling.
Kotlin EventChannel
↓
Flutter Stream
↓
BLoC / Riverpod / Provider
↓
UI
5. Keep AI platform-independent
Flutter can send normalized events to a backend:
Future<String> askAssistant(String text) async {
// Call your backend API.
return 'response';
}
6. Handle Android-only features
Keep XR-specific code in:
android/app/src/main/kotlin/.../xr/
This prevents Android XR dependencies from leaking into shared application code.
Conclusion
Flutter and Kotlin form a useful combination for cross-platform wearable products: Flutter owns shared product logic and UI, while Kotlin owns Android-specific XR integration.
Useful Links
Website: www.v-modal.com
SDK Flutter: https://github.com/v-modal/vmodal_sdk_flutter
SDK Android: https://github.com/v-modal/vmodal_sdk_android
Discord: https://discord.gg/K72z28KUx
Top comments (0)