aerosync_flutter_sdk 2.0.0-dev aerosync_flutter_sdk: ^2.0.0-dev copied to clipboard
This Flutter SDK provides an interface to load Aerosync-UI in Flutter apps.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:aerosync_flutter_sdk/aerosync_flutter_sdk.dart';
void main() => runApp(UrlLauncherPage());
class UrlLauncherPage extends StatefulWidget {
UrlLauncherPage({Key? key}) : super(key: key);
@override
UrlLauncherExample createState() => UrlLauncherExample();
}
class UrlLauncherExample extends State<UrlLauncherPage> {
static const String _title = 'URL Launcher Example';
late String _token = "";
late String _env = "dev";
late String _deeplink = "";
late String _configurationId = "";
late String _aeroPassUserUuid = "";
late bool _handleMFA = false;
late String _jobId = "";
late String _userId = "";
Map _style = {};
late bool isLoading;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: isLoading
? LaunchButton(
env: _env,
token: _token,
style: _style,
deeplink: _deeplink,
configurationId: _configurationId,
aeroPassUserUuid: _aeroPassUserUuid,
handleMFA: _handleMFA,
jobId: _jobId,
userId: _userId,
)
: SizedBox(), // this includes all the button and functionality
),
);
}
@override
void initState() {
super.initState();
isLoading = false;
}
}
class LaunchButton extends StatelessWidget {
var env;
var token;
var style;
var deeplink;
var configurationId;
var aeroPassUserUuid;
var handleMFA;
var jobId;
var userId;
LaunchButton(
{Key? key,
required this.env,
required this.token,
required this.style,
required this.deeplink,
this.configurationId,
this.aeroPassUserUuid,
this.handleMFA,
this.jobId,
this.userId})
: super(key: key);
// handle the OnEvent callback from aerosync
handleOnEventAerosync(eventType, data) {
print("CALLBACK FULLY HANDLED: OnEvent");
}
// handle the OnSuccess callback from aerosync
handleOnSuccessAerosync(eventType, data) {
print("CALLBACK FULLY HANDLED: OnSuccess");
Map<String, dynamic> successData = jsonDecode(data);
print(data);
}
// handle the OnClose callback from aerosync
handleOnCloseAerosync(eventType, data) {
print("CALLBACK FULLY HANDLED: OnClose");
}
// handle the OnLoad callback from aerosync
handleOnLoadAerosync(eventType, data) {
print("CALLBACK FULLY HANDLED: OnLoad");
}
// handle the OnError callback from aerosync
handleOnErrorAerosync(eventType, data) {
print("CALLBACK FULLY HANDLED: OnError");
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => AerosyncSDKPage(
env: env,
token: token,
style: style,
onEvent: handleOnEventAerosync,
onSuccess: handleOnSuccessAerosync,
onClose: handleOnCloseAerosync,
onLoad: handleOnLoadAerosync,
onError: handleOnErrorAerosync,
deeplink: deeplink,
configurationId: configurationId,
aeroPassUserUuid: aeroPassUserUuid,
handleMFA: handleMFA,
jobId: jobId,
userId: userId,
)))
},
child: Text(
'Connect',
style: TextStyle(fontSize: 20),
),
),
],
));
}
}