smooch_plugin 2.0.3 smooch_plugin: ^2.0.3 copied to clipboard
Smooch resources on Flutter
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:smooch_plugin/smooch_constants.dart';
import 'package:smooch_plugin/smooch_plugin.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static const String START_SMOOCH_ACTION = "android.intent.action.START_SMOOCH";
static const _channel = MethodChannel("app_state");
Future<String> _startAction;
int _count = -1;
void _updateUnreadCount(count) {
setState(() {
_count = count;
});
}
void _handleMessageAction(uri) {
print(uri);
}
void _logoutComplete(logoutResult) {
print("onLogoutComplete");
}
void _onHelpClick() {
print("onHelpClick");
}
@override
void initState() {
super.initState();
_startAction = _getStartAction();
if (mounted) initPlatformState();
}
Future<String> _getStartAction() async {
try {
return _channel.invokeMethod("getStartAction");
} on PlatformException catch (e) {
print("Failed to Invoke: '${e.message}'.");
return "unknown";
}
}
Future<void> initPlatformState() async {
SmoochPlugin.initializeChannel(onUpdateUnreadCount: _updateUnreadCount, onHandleMessageAction: _handleMessageAction, onLogout: _logoutComplete, onHelpClick: _onHelpClick);
String chatColor = "009900";
List<String> menuItemsAllowed = [
SKTMenuItemCamera,
SKTMenuItemDocument,
SKTMenuItemGallery,
SKTMenuItemLocation,
];
try {
final bool result = await SmoochPlugin.init(
appId: "5a03043874d36900511723cc",
userId: "387588",
smoochToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcF81YmIzN2QzOGMyYzIwMTAwMjI3M2YyMjgifQ.eyJzY29wZSI6ImFwcFVzZXIi"
"LCJ1c2VySWQiOiIzODc1ODgiLCJpYXQiOjE1NzQzNDgwMjZ9.bCsUuOAc4_k8HCIIkJ7XUQM7RPPrRd23B3JIt5Z0DJA",
chatColor: chatColor,
menuItemsAllowed: menuItemsAllowed);
if (result == false) {
print("Failed to initialize smooch");
return;
}
_startAction.then((action) {
print("action received: $action");
if (action == START_SMOOCH_ACTION) {
SmoochPlugin.show(lang: "en");
}
});
} on PlatformException catch (e) {
print('Exception: $e');
}
}
Future<void> showSmooch() async {
try {
await SmoochPlugin.show(lang: "es", sendStart: true);
// Future.delayed(Duration(milliseconds: 5000), () async {
// print("trying to minimize");
// await SmoochPlugin.minimize();
// });
} on PlatformException catch (e) {
print('Exception: $e');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Smooch plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
FlatButton(
onPressed: showSmooch,
child: Text("Abrir smooch"),
),
Text('Unread messages count: $_count')
],
),
),
),
);
}
}