unifyapps_sdk_flutter 0.0.2
unifyapps_sdk_flutter: ^0.0.2 copied to clipboard
UnifyApps SDK Flutter
UnifyApps Flutter SDK #
A powerful Flutter SDK that enables seamless integration of UnifyApps into your mobile applications with built-in authentication, dynamic data handling, and real-time communication.
Overview #
The UnifyApps Flutter SDK provides a Flutter widget that connects your mobile app to UnifyApps platforms. It handles user authentication, data synchronization, and bi-directional communication between your Flutter app and UnifyApps.
Key Features #
🔐 Secure Authentication #
- Token-based authentication system
- Identity provider integration
- Automatic session management
- Secure credential handling
📡 Real-time Communication #
- Bi-directional event system
- Listen to app events and user interactions
- Send data updates from Flutter App to UnifyApps SDK.
🔄 Dynamic Data Management #
- Pass initial data to UnifyApps on load
- Update data in real-time
Installation #
Add the SDK to your Flutter project:
dependencies:
unifyapps_sdk_flutter: ^0.0.1
Install the package:
flutter pub get
Getting Started #
Basic Integration #
Create a short lived session id and pass it to the UnifyApps Flutter SDK.
curl --location '<HOST_URL>/auth/createUserExternalLoginSession' \
--header 'user-agent: Dart/3.8 (dart:io)' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer <AUTH_TOKEN>' \
--header 'x-ua-app: dda-copilot-app' \
--data '{
"identityProviderId": "<IDENTITY_PROVIDER_ID>",
"formData": {
"username":"<USERNAME>",
"name": "<NAME>"
}
}'
Sample response:
{
sessionId: "<SESSION_ID>"
}
Pass the above session id in the UnifyApps Widget as shown below:
import 'package:flutter/material.dart';
import 'package:unifyapps_sdk_flutter/unifyapps_sdk_flutter.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('My UnifyApp')),
body: UnifyAppsWidget(
host: '<HOST_URL>',
sessionId: '<SESSION_ID>'
pageId: '<PAGE_ID>',
pageInputs: <String, dynamic>{
'key1': 'value1',
'key2': 42,
},
),
);
}
}
API Reference #
UnifyAppsWidget #
The main widget for integrating UnifyApps into your Flutter application.
Constructor Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
String |
Yes | The UnifyApps host URL |
sessionId |
String |
Yes | Short lived SessionId |
pageId |
String? |
No | Specific page to navigate to |
pageInputs |
Map<String, dynamic>? |
No | Initial data to pass to the application |
onPageEvent |
Function(String)? |
No | Callback for handling app events |
Advanced #
Dynamic Data Updates #
Use a GlobalKey to access the widget's state and update data dynamically:
class DynamicDataExample extends StatefulWidget {
@override
_DynamicDataExampleState createState() => _DynamicDataExampleState();
}
class _DynamicDataExampleState extends State<DynamicDataExample> {
final GlobalKey<UnifyAppsWidgetState> _appKey = GlobalKey<UnifyAppsWidgetState>();
void updateUserData() {
final newData = <String, dynamic>{
'key1': 'value1',
'key2': 42,
},
_appKey.currentState.updatePageInputs(newData);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dynamic Updates'),
actions: [
IconButton(
icon: Icon(Icons.refresh),
onPressed: updateUserData,
),
],
),
body: UnifyAppsWidget(
appKey: _appKey,
host: '<HOST_URL>',
sessionId: '<SESSION_ID>',
pageId: '<PAGE_ID>',
pageInputs: <String, dynamic>{
'key1': 'value1',
'key2': 42,
},
),
);
}
}
Event-Driven Architecture #
Detect Page events from UnifyApps App.
class EventDrivenExample extends StatefulWidget {
@override
_EventDrivenExampleState createState() => _EventDrivenExampleState();
}
class _EventDrivenExampleState extends State<EventDrivenExample> {
final GlobalKey<UnifyAppsWidgetState> _appKey = GlobalKey<UnifyAppsWidgetState>();
List<String> notifications = [];
void handleAppEvent(String event) {
final event = jsonDecode(event);
// Respond to specific events
if (event == 'session_expired') {
_appKey.currentState?.updatePageInputs({
'session_id': getNewSessionId(),
});
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Notifications area
Container(
height: 100,
child: ListView.builder(
itemCount: notifications.length,
itemBuilder: (context, index) => Text(notifications[index]),
),
),
// UnifyApps
Expanded(
child: UnifyAppsWidget(
key: _appKey,
host: "<HOST_URL>",
onPageEvent: handleAppEvent,
),
),
],
);
}
}
Platform Support #
- ✅ iOS (12.0+)
- ✅ Android (API 21+)
Requirements #
- Flutter SDK 3.0.0 or higher
- Dart 3.8.1 or higher