Embed Flutter SDK Integration Guide
Overview
The Embed Flutter SDK is a powerful voice-enabled AI agent library that provides real-time widget tree monitoring for screen context fetching and real-time voice communication. This comprehensive guide will walk you through the complete integration process from installation to deployment.Prerequisites
- Flutter 3.0+
- Dart 2.17+
- Platform specific:
- iOS 12.0+
- Android API 21+
- Device with microphone capabilities
This SDK requires proper setup of device permissions and real-time communication dependencies for voice functionality.
Installation
Add the following dependency to yourpubspec.yaml:
Android Configuration
CRITICAL: Add all required permissions to your Android manifest. Missing permissions will cause the voice functionality to fail.
android/app/src/main/AndroidManifest.xml:
iOS Configuration
CRITICAL: Add the following permissions to your
ios/Runner/Info.plist. Missing NSMicrophoneUsageDescription will cause the app to crash when accessing the microphone.ios/Runner/Info.plist:
SDK Initialization
embedInitialize Function
CRITICAL: Always initialize the SDK before using any EmbedWidget. Missing initialization will cause the widget to fail.
EmbedWidget, you must initialize the configuration once in your main.dart:
Configuration Options
| Property | Type | Required | Description |
|---|---|---|---|
apiKey | String | ✅ | Your Embed API key |
embedUrl | String | ❌ | Custom base URL for API endpoints |
App Setup
1. Required: Navigator Observer
CRITICAL: For route-based activation to work properly, you must add
EmbedNavigatorObserver to your app’s navigator observers. This enables the SDK to track route changes and activate/deactivate the EmbedWidget accordingly.2. Wrap Main App with EmbedWidget
Wrap your main app content withEmbedWidget:
Event System
The SDK provides a powerful event system to send user context and application state to the AI agent. There are two main event types that must be used correctly:Available Events
Sending Events (EventKeys)
Event Usage Rules
CRITICAL REQUIREMENTS:
- USER_DATA event MUST be sent first before any other events or EmbedWidget functionality
- USER_DATA must include
app_user_idfor user identification - SCREEN_STATE events can only be sent after USER_DATA is established
- EmbedWidget will not be fully functional until USER_DATA event is sent
Required: USER_DATA Event
To activate the EmbedWidget and enable voice functionality, you must send theUSER_DATA event with a user ID. This is typically done after user authentication:
Optional: SCREEN_STATE Event
You can optionally sendSCREEN_STATE events to provide additional context about screen changes or user navigation:
Event Flow Example
Event Summary Table
| Event | Purpose | Required | When to Use |
|---|---|---|---|
USER_DATA | Initialize user context and activate EmbedWidget | Required | After user authentication or when user ID is available |
SCREEN_STATE | Provide screen context and navigation info | Optional | When navigating between screens or when screen context changes |
Route-Based Activation
The SDK supports intelligent route-based activation, allowing you to control exactly which screens should display the EmbedWidget:Route Configuration Options
enabledRoutes: List of route names where EmbedWidget should be activeshowOnAllRoutes: Show EmbedWidget on all routes (default:false)disabledRoutes: List of route names where EmbedWidget should be disabledrouteMatchMode: How to match routes (RouteMatchMode.exact,RouteMatchMode.startsWith, orRouteMatchMode.contains)
Required Parameters
child(required): The main content of your app
Optional Parameters
apiKey(optional): Your Revrag AI API key for authentication (can be set globally viaembedInitialize())embedUrl(optional): Custom base URL for API endpoints (can be set globally viaembedInitialize())showEmbedWidget(default:true): Controls whether the embedded widget is visibleenabledRoutes(optional): List of route names where EmbedWidget should be activeshowOnAllRoutes(default:false): Show EmbedWidget on all routesdisabledRoutes(optional): List of route names where EmbedWidget should be disabledrouteMatchMode(default:RouteMatchMode.exact): How to match routes
Examples
Basic Integration
Form with Monitoring
Route-Based Configuration
Configure the EmbedWidget to activate only on specific screens:Custom Router Integration
Full integration with GoRouter for declarative navigation:Configuration
Custom Base URL
You can set a custom base URL globally during initialization:Troubleshooting
Common Issues
User identity not found error
User identity not found error
This error occurs when you try to use EmbedWidget functionality before sending USER_DATA:
- ✅ Send
USER_DATAevent first withapp_user_id - ✅ Wait for the event to complete before using other features
- ✅ Only use EmbedWidget after USER_DATA is sent
Widget not appearing
Widget not appearing
Check these requirements:
- ✅ SDK initialized successfully (
embedInitialize()called) - ✅ Valid API key provided
- ✅ USER_DATA event sent with valid
app_user_id - ✅ Required permissions granted
- ✅ Network connectivity available
- ✅
showEmbedWidgetparameter set to true
iOS App Crashes - microphone permission
iOS App Crashes - microphone permission
This crash occurs when the app tries to access the microphone without proper permission:
- ✅ Open
ios/Runner/Info.plist - ✅ Add
NSMicrophoneUsageDescriptionwith a user-friendly description:
- ✅ Clean and rebuild:
flutter clean && flutter pub get && flutter run
Voice calls not working
Voice calls not working
This issue is usually related to device permissions or network configuration:
- ✅ Ensure all Android/iOS permissions are added to manifest/Info.plist
- ✅ Check device microphone permissions in Settings
- ✅ Verify network connectivity
- ✅ Test on physical device (not simulator/emulator)
- ✅ Check if USER_DATA event was sent successfully
Route-based activation not working
Route-based activation not working
Verify route tracking is properly configured:
- ✅ Verify route names match exactly (case-sensitive)
- ✅ Check
EmbedNavigatorObserveris added to navigator observers - ✅ Ensure GoRouter is properly configured with named routes
- ✅ Verify
enabledRouteslist contains correct route names
Widget tree not updating
Widget tree not updating
Verify widget tree monitoring is working:
- ✅ Verify
EmbedWidgetwraps your main content - ✅ Check that widget context is available
- ✅ Ensure proper widget disposal
- ✅ Test with simple widget hierarchy first
- ✅ Verify USER_DATA event was sent
Events not working
Events not working
Common issues with event sending:
- ✅ Ensure USER_DATA is sent first:
- ✅ Check network connectivity and API endpoint
- ✅ Verify API key is valid and has proper permissions
- ✅ Handle async operations properly with try-catch:
Performance issues
Performance issues
Check widget tree optimization:
- ✅ Avoid deeply nested widget trees
- ✅ Use const constructors where possible
- ✅ Check for memory leaks in event listeners
- ✅ Monitor app performance metrics
- ✅ Limit frequency of SCREEN_STATE events
Best Practices
Event Optimization:
- Send USER_DATA event as early as possible in the app lifecycle
- Debounce frequent SCREEN_STATE events to avoid overwhelming the API
- Handle offline scenarios with retry logic
- Store critical events locally when network is unavailable
Initialization Strategy:
- Show loading states during SDK initialization
- Handle initialization errors gracefully
- Only render EmbedWidget after successful initialization and USER_DATA event
- Test initialization on various network conditions
Performance Optimization:
- Use const constructors to reduce widget rebuilds
- Avoid deeply nested widget hierarchies
- Implement proper widget disposal in
dispose()methods - Monitor memory usage and optimize accordingly
- Limit widget tree depth for better monitoring performance
Security & Privacy:
- Store API keys securely using flutter_secure_storage
- Request only necessary permissions with clear explanations
- Validate all user inputs before processing
- Use HTTPS endpoints in production
- Never expose API keys in client-side code
User Experience:
- Show loading states during SDK initialization
- Provide clear permission request explanations
- Handle offline scenarios gracefully
- Test voice functionality on various devices and network conditions
- Provide fallback UI when voice features are unavailable
Support
For additional help:- Email Support: contact@revrag.ai
Last Updated: September 2025