Flutter Integration
Current Flutter Persona guide covering initializeApiKey, the Onairos widget, deep links, and the wrapper callback shape.
Flutter Integration
Use the onairos Flutter package when you want the current wrapper flow in a Flutter app.
The current high-level Flutter wrapper uses initializeApiKey(...), the Onairos widget, and onResolved(apiUrl, token, userData). Do not copy the React Native onComplete examples into Flutter.
1. Install the package
dart pub add onairos
2. Initialize the SDK
import 'package:onairos/initialize_api_key.dart';
await initializeApiKey(
apiKey: 'your_api_key',
environment: 'production',
);
3. Register your deep link / URL scheme
Set up your app's URL scheme on iOS and Android, then pass the scheme string into returnLink. If your callback is yourapp://callback, pass yourapp as the returnLink value.
4. Render the high-level widget
import 'package:flutter/material.dart';
import 'package:onairos/initialize_api_key.dart';
import 'package:onairos/onairos.dart';
class OnairosDemo extends StatefulWidget {
const OnairosDemo({super.key});
@override
State<OnairosDemo> createState() => _OnairosDemoState();
}
class _OnairosDemoState extends State<OnairosDemo> {
@override
void initState() {
super.initState();
initializeApiKey(apiKey: 'your_api_key');
}
@override
Widget build(BuildContext context) {
return Onairos(
AppName: 'YourApp',
returnLink: 'yourapp',
googleClientId: 'your-google-client-id.apps.googleusercontent.com',
requestData: {
'basic': {
'name': 'Basic Profile',
'description': 'Required account basics',
'reward': 'Required'
},
'preferences': {
'name': 'Preferences',
'description': 'Use inferred tastes in your app',
'reward': 'Better recommendations'
},
'personality': {
'name': 'Personality',
'description': 'Use traits and summaries in your app',
'reward': 'Deeper personalization'
}
},
onResolved: (apiUrl, token, userData) {
print(apiUrl);
print(token);
print(userData['apiResponse']);
},
);
}
}
Main wrapper inputs
| Prop | Required | What it does |
|---|---|---|
AppName | Yes | The app name shown inside the Flutter wrapper flow. |
returnLink | Yes | Your app's URL scheme. The wrapper expects the callback to come back through that scheme. |
requestData | No | Map-shaped consent copy shown in the flow. The current consent screen centers on basic, preferences, and personality. |
onResolved | No | Called as onResolved(apiUrl, token, userData) when the flow finishes. |
googleClientId | No | Provide this when you need YouTube / Google sign-in inside the Flutter flow. |
The current Flutter package still exposes some legacy naming. Older examples may show personality_traits, sentiment_analysis, or auto; the current docs path uses the built-in consent ids basic, preferences, and personality.
Connector customization
- The current high-level Flutter wrapper does not expose a public
allowedPlatformsorrecommendedPlatformsAPI like React Native. - The wrapper currently ships with its own built-in connector set and ordering.
preferredPlatformis threaded into the modal flow, but it is not applied inside the currentNpmUniversalOnboardingscreen. Do not rely on it to reorder the connector UI.
What the callback gives you
The Flutter wrapper completes through onResolved(apiUrl, token, userData). The main values are:
| Argument | Meaning |
|---|---|
apiUrl | The returned API URL for the approved request |
token | Short-lived token for that returned API URL |
userData | User/session details plus any merged flow data the wrapper collected, including fetched response fields when the internal data request completes |
Manual fetch example
final response = await http.post(
Uri.parse(apiUrl),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
},
body: jsonEncode({
'Input': {
'item1': {'text': 'Example content', 'category': 'general'}
}
}),
);
Use Inference API if you want to call the returned route yourself after the Flutter flow completes.