aerosync_flutter_sdk 1.1.0 aerosync_flutter_sdk: ^1.1.0 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 _consumerId = "";
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,
consumerId: _consumerId,
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 consumerId;
var handleMFA;
var jobId;
var userId;
LaunchButton(
{Key? key,
required this.env,
required this.token,
required this.style,
required this.deeplink,
this.consumerId,
this.handleMFA,
this.jobId,
this.userId})
: super(key: key);
// handle the OnEvent callback from aerosync
handleOnEventAerosync(eventType, data) {
}
// handle the OnSuccess callback from aerosync
handleOnSuccessAerosync(eventType, data) {
Map<String, dynamic> successData = jsonDecode(data);
print(data);
}
// handle the OnClose callback from aerosync
handleOnCloseAerosync(eventType, data) {
}
// handle the OnLoad callback from aerosync
handleOnLoadAerosync(eventType, data) {
}
// handle the OnError callback from aerosync
handleOnErrorAerosync(eventType, data) {
}
@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,
consumerId: consumerId,
handleMFA: handleMFA,
jobId: jobId,
userId: userId,
)))
},
child: Text(
'Connect',
style: TextStyle(fontSize: 20),
),
),
],
));
}
}