A plugin that translates the Intercom SDK into a plugin for Flutter
Import package:intercom_plugin/intercom_plugin.dart and use the methods in Intercom class.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:intercom_plugin/intercom_plugin.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
Intercom.initialize(
androidApiKey: 'ANDROID API KEY',
iOSApiKey: 'iOS API KEY',
appId: 'YOUR APP ID'
);
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
FlatButton(
child: Text("Display messenget"),
onPressed: () async{
await Intercom.displayMessenger();
},
),
FlatButton(
child: Text("Logs a event"),
onPressed: () async{
await Intercom.logEvent("First event", metadata: {
"meta":"data"
});
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("Event logged with success"),
)
);
},
)
],
),
),
),
);
}
}
First you need to add this permission
<uses-permission android:name="android.permission.INTERNET"/>
Other permissions that you can set, but is optional
<manifest>
...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
...
</manifest>
This plugin allows push notifications for Intercom and FCM. You can explore better in the IntercomInterceptor.kt file, but basically, we verify if the push is coming from Intercom and pass to him the responsability to handle the push, otherwise FCM will handle it.
- First, implement the firebase_messaging and take a look in the android part.
- Then, add the Firebase server key to Intercom, as described here (you can skip 1 and 2)
- Lastly, add this to you AndroidManifest.xml, above the closing tag
<service
android:name="dev.lucaseduardo.intercom_plugin.IntercomInterceptor"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>