unifyapps_sdk_flutter 0.0.8
unifyapps_sdk_flutter: ^0.0.8 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
- WebView preloading for improved performance
Installation #
Add the SDK to your Flutter project:
dependencies:
unifyapps_sdk_flutter: ^0.0.8
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 |
Preloading Support #
For improved performance, you can preload the WebView before displaying it:
// Preload the widget
final preloadedWidget = preloadUnifyAppsWidget(
host: '<HOST_URL>',
sessionId: '<SESSION_ID>',
pageId: '<PAGE_ID>',
pageInputs: <String, dynamic>{
'key1': 'value1',
'key2': 42,
},
onPageEvent: (event) {
print('Received event: $event');
},
);
// Use the preloaded widget
UnifyAppsWidget.preloaded(
preloadedWidget: preloadedWidget,
onPageEvent: (event) {
print('Received event: $event');
},
)
Advanced #
Copilot Example #
To dynamically update pageInputs at runtime from your Flutter app, use the UnifyAppsController.
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CopilotExample()),
);
},
child: Container(
color: Colors.white, // Set the background behind Scaffold to white
child: Scaffold(
backgroundColor:
Colors.transparent, // Make Scaffold background transparent
body: SafeArea(
top: true,
bottom: true,
child: SizedBox.expand(
child: Image.asset('assets/home_screen.jpg', fit: BoxFit.fill),
),
),
),
),
);
}
}
class CopilotExample extends StatefulWidget {
@override
_CopilotExampleState createState() => _CopilotExampleState();
}
class _CopilotExampleState extends State<CopilotExample> {
final UnifyAppsController _uaController = UnifyAppsController();
void updateUserData() {
final newData = <String, dynamic>{
'key1': 'value1',
'key2': 42,
},
_uaController.updatePageInputs(newData);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Copilot Example'),
actions: [
IconButton(
icon: Icon(Icons.refresh),
onPressed: updateUserData,
),
],
),
body: UnifyAppsWidget(
appKey: _appKey,
host: '<HOST_URL>',
sessionId: '<SESSION_ID>',
pageId: '<PAGE_ID>',
controller: _uaController,
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 UnifyAppsController _uaController = UnifyAppsController();
List<String> notifications = [];
void handleAppEvent(String event) {
final event = jsonDecode(event);
// Respond to specific events
if (event == 'session_expired') {
_uaController.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,
controller: _uaController
),
),
],
);
}
}
Preloaded Widget Example #
For better performance, preload the WebView:
class PreloadedExample extends StatefulWidget {
@override
_PreloadedExampleState createState() => _PreloadedExampleState();
}
class _PreloadedExampleState extends State<PreloadedExample> {
late Future<PreloadedUnifyAppsWidget> _preloadedWidget;
@override
void initState() {
super.initState();
_preloadedWidget = preloadUnifyAppsWidget(
host: '<HOST_URL>',
sessionId: '<SESSION_ID>',
pageId: '<PAGE_ID>',
pageInputs: <String, dynamic>{
'key1': 'value1',
'key2': 42,
},
onPageEvent: (event) {
print('Received event: $event');
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Preloaded Example')),
body: UnifyAppsWidget.preloaded(
preloadedWidget: _preloadedWidget,
onPageEvent: (event) {
print('Received event: $event');
},
),
);
}
}
Platform Support #
- β iOS (12.0+)
- β Android (API 21+)
Requirements #
- Flutter SDK 3.0.0 or higher
- Dart 3.8.1 or higher
Changelog #
Version 0.0.2 #
- New API Structure: Completely redesigned API for better performance and flexibility
- WebView Preloading: Added support for preloading WebView widgets to improve load times
- Performance Optimizations: Various performance improvements and memory management enhancements
- Backward Compatibility: All existing APIs remain compatible with the new implementation
Version 0.0.1 #
- Initial release with basic UnifyApps integration