|
| 1 | +# firebase_in_app_messaging plugin |
| 2 | + |
| 3 | +A Flutter plugin to use the [Firebase In-App Messaging API](https://firebase.google.com/products/in-app-messaging). |
| 4 | + |
| 5 | +*Note*: This plugin is still under development, and some APIs might not be available yet. [Feedback](https://github.com/FirebaseExtended/flutterfire/issues) and [Pull Requests](https://github.com/FirebaseExtended/flutterfire/pulls) are most welcome! |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +### Import the firebase_in_app_messaging plugin |
| 10 | +To use the firebase_in_app_messaging plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_in_app_messaging#pub-pkg-tab-installing). |
| 11 | + |
| 12 | +### Android integration |
| 13 | + |
| 14 | +There are a few extra steps required for the Android integration. Enable the Google services by configuring the Gradle scripts as such. |
| 15 | + |
| 16 | +1. Add the classpath to the `[project]/android/build.gradle` file. |
| 17 | +```gradle |
| 18 | +dependencies { |
| 19 | + // Example existing classpath |
| 20 | + classpath 'com.android.tools.build:gradle:3.3.0' |
| 21 | + // Add the google services classpath |
| 22 | + classpath 'com.google.gms:google-services:4.3.0' |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +2. Add the apply plugin to the `[project]/android/app/build.gradle` file. |
| 27 | +```gradle |
| 28 | +// ADD THIS AT THE BOTTOM |
| 29 | +apply plugin: 'com.google.gms.google-services' |
| 30 | +``` |
| 31 | + |
| 32 | +*Note:* If this section is not completed you will get an error like this: |
| 33 | +``` |
| 34 | +java.lang.IllegalStateException: |
| 35 | +Default FirebaseApp is not initialized in this process [package name]. |
| 36 | +Make sure to call FirebaseApp.initializeApp(Context) first. |
| 37 | +``` |
| 38 | + |
| 39 | +*Note:* When you are debugging on Android, use a device or AVD with Google Play services. |
| 40 | +Otherwise you will not be able to use Firebase In-App Messaging. |
| 41 | + |
| 42 | +### Use the plugin |
| 43 | + |
| 44 | +To show In-App Messages in your app, no extra setup is required - just import the plugin and you |
| 45 | +are good to go. However, to modify message behavior (as documented [here](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior)), the plugin provides the following methods - |
| 46 | + |
| 47 | +First off, add the following imports to your Dart code: |
| 48 | +```dart |
| 49 | +import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart'; |
| 50 | +``` |
| 51 | + |
| 52 | +#### Programmatic Triggers ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#trigger_in-app_messages_programmatically)) |
| 53 | + |
| 54 | +To trigger in-app messages programmatically |
| 55 | + |
| 56 | +```dart |
| 57 | +FirebaseInAppMessaging.triggerEvent('eventName'); |
| 58 | +``` |
| 59 | + |
| 60 | +#### Temporarily disable in-app messages ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#temporarily_disable_in-app_messages)) |
| 61 | + |
| 62 | +If you'd like to suppress message displays for any reason, for example to avoid interrupting a sequence of payment processing screens, you can do that the following |
| 63 | + |
| 64 | +```dart |
| 65 | +FirebaseInAppMessaging.setMessagesSuppressed(true); |
| 66 | +
|
| 67 | +
|
| 68 | +// To re-enable |
| 69 | +FirebaseInAppMessaging.setMessagesSuppressed(false); |
| 70 | +``` |
| 71 | + |
| 72 | +#### Enable opt-out message delivery ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#enable_opt-out_message_delivery)) |
| 73 | + |
| 74 | +First, follow the step outlined [here](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior#enable_opt-out_message_delivery) for both iOS and Android. Then add the following code in your app: |
| 75 | + |
| 76 | +```dart |
| 77 | +FirebaseInAppMessaging.setAutomaticDataCollectionEnabled(false); |
| 78 | +``` |
| 79 | + |
| 80 | +## Example |
| 81 | + |
| 82 | +See the [example application](https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_in_app_messaging/example) source |
| 83 | +for a complete sample app using the Firebase In-App Messaging. |
| 84 | + |
| 85 | +## Issues and feedback |
| 86 | + |
| 87 | +Please file [issues](https://github.com/flutter/flutter/issues/new) |
| 88 | +to send feedback or report a bug. Thank you! |
0 commit comments