engage_plugin 1.0.0 engage_plugin: ^1.0.0 copied to clipboard
A flutter plugin for the engage SDK's
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:engage_plugin/engage_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _engagePlugin = EngagePlugin();
@override
void initState() {
super.initState();
initPlatformState();
}
var tenantId = "";
var token = "";
var serverUrl = "";
var cdnServerUrl = "";
Future<void> initPlatformState() async {
try {
await _engagePlugin.init(tenantId, token);
} on PlatformException {
'failed to init engage';
}
/* If you want to use a custom server please comment the init function and uncomment this one */
// try {
// await _engagePlugin.initWithCustomServer(
// tenantId, token, serverUrl, cdnServerUrl);
// } on PlatformException {
// 'failed to init engage';
// }
if (!mounted) {
return;
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Engage plugin example'),
),
body: Center(
child: Column(
children: [
ElevatedButton(
onPressed: (() => _engagePlugin.init(tenantId, token)),
child: const Text('Init Plugin')),
/* If you want to use a custom server please comment the init button and uncomment this one */
// ElevatedButton(
// onPressed: (() => _engagePlugin.initWithCustomServer(
// tenantId, token, serverUrl, cdnServerUrl)),
// child: const Text('Init Plugin custom server')),
ElevatedButton(
onPressed: () => _engagePlugin.openChat(),
child: const Text('Open Chat')),
ElevatedButton(
onPressed: () => _engagePlugin.startCoBrowsing(),
child: const Text('Open coBrowser')),
ElevatedButton(
onPressed: () => _engagePlugin.stopCoBrowsing(),
child: const Text('Stop coBrowser')),
ElevatedButton(
onPressed: () => _engagePlugin.tagUser(),
child: const Text('Tag user')),
ElevatedButton(
onPressed: () => _engagePlugin.tagUserA(),
child: const Text('Tag user A')),
],
)),
),
);
}
}