DEV Community

vmodal_ai
vmodal_ai

Posted on

Android XR + Flutter: Building Cross-Platform Smart Glasses Experiences

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
Enter fullscreen mode Exit fullscreen mode

1. Create the Flutter channel

static const channel = MethodChannel('xr/device');

Future<bool> isAvailable() async {
  return await channel.invokeMethod('isAvailable') ?? false;
}
Enter fullscreen mode Exit fullscreen mode

2. Implement Kotlin

MethodChannel(
    flutterEngine.dartExecutor.binaryMessenger,
    "xr/device"
).setMethodCallHandler { call, result ->
    when (call.method) {
        "isAvailable" -> result.success(true)
        else -> result.notImplemented()
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Create a service layer

class XrService {
  Future<bool> available() => XrBridge.isAvailable();
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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';
}
Enter fullscreen mode Exit fullscreen mode

6. Handle Android-only features

Keep XR-specific code in:

android/app/src/main/kotlin/.../xr/
Enter fullscreen mode Exit fullscreen mode

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

Reddit: https://www.reddit.com/r/v_modal/

Top comments (0)