LiveChat is a plugin that brings LiveChat functionality to Flutter Mobile and Web.
First, add live_chat_plus
as a dependency in your pubspec.yaml file.
Step 1: Ensure you have added Internet permission in AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET"/>
Step 2: To avoid issues with proguard enabled, include the following to proguard.pro file:
-keep class com.livechatinc.inappchat.** { *; }
Inside index.html file, add this line inside <head></head>
tag:
<script src="./assets/packages/live_chat_plus/assets/live_chat.js" defer></script>
- To start, import the following:
import 'package:live_chat_plus/live_chat_plus.dart';
- To open the chat window, call openChatView as follows:
await LiveChat().openChatWindow(
licenseId: '<LICENSE ID>',
username: '<USERNAME>',
email: '<EMAIL>',
groupId: '<GROUP ID>',
customParameters: <String, String>{'CUSTOM KEY': 'CUSTOM VALUE'},
);
- You can subscribe to an event stream to listen to events coming from livechat.
LiveChat().onLiveChatEventReceived?.listen((event) {
switch (event) {
case 'chatOpen':
break;
case 'chatClose':
break;
default:
// Messages - You can handle notification badge counts for example here.
}
});
- You call close the chat window by simply calling:
LiveChat().closeChatWindow();
- In order to clear the session in mobile, for example, after logging out, you can call:
LiveChat().clearChatSession();
This will call destroy on web.
Refer to the example folder for a working app. Just ensure you have a valid license id.