-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[firebase_in_app_messaging] add new plugin #1791
Changes from 16 commits
6127d09
3c46be0
d5ceda4
a61554b
37fb5f7
da2c34d
82f41f8
3a89c02
8d810d3
2d8f9a9
d507113
ee0ea7a
7c82b7f
1bce955
64eb8a7
1a769fc
d71ff60
00fee03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .DS_Store | ||
| .dart_tool/ | ||
|
|
||
| .packages | ||
| .pub/ | ||
|
|
||
| build/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file tracks properties of this Flutter project. | ||
| # Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| # | ||
| # This file should be version controlled and should not be manually edited. | ||
|
|
||
| version: | ||
| revision: 2e540931f73593e35627592ca4f9a4ca3035ed31 | ||
| channel: stable | ||
|
|
||
| project_type: plugin |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## 0.0.1 | ||
|
|
||
| * TODO: Describe initial release. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| Copyright 2018, the Chromium project authors. All rights reserved. | ||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are | ||
| met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer in the documentation and/or other materials provided | ||
| with the distribution. | ||
| * Neither the name of Google Inc. nor the names of its | ||
| contributors may be used to endorse or promote products derived | ||
| from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,90 @@ | ||||||
| # firebase_inappmessaging plugin | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||
|
|
||||||
| A Flutter plugin to use the [Firebase In-App Messaging API](https://firebase.google.com/products/in-app-messaging). | ||||||
|
|
||||||
| For Flutter plugins for other Firebase products, see [FlutterFire.md](https://github.com/flutter/plugins/blob/master/FlutterFire.md). | ||||||
|
|
||||||
| *Note*: This plugin is still under development, and some APIs might not be available yet. [Feedback](https://github.com/flutter/flutter/issues) and [Pull Requests](https://github.com/flutter/plugins/pulls) are most welcome! | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| ### Import the firebase_inappmessaging plugin | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||
| To use the firebase_inappmessaging plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_inappmessaging#pub-pkg-tab-installing). | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||
|
|
||||||
| ### Android integration | ||||||
|
|
||||||
| There are a few extra steps required for the Android integration. Enable the Google services by configuring the Gradle scripts as such. | ||||||
|
|
||||||
| 1. Add the classpath to the `[project]/android/build.gradle` file. | ||||||
| ```gradle | ||||||
| dependencies { | ||||||
| // Example existing classpath | ||||||
| classpath 'com.android.tools.build:gradle:3.3.0' | ||||||
| // Add the google services classpath | ||||||
| classpath 'com.google.gms:google-services:4.2.0' | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| 2. Add the apply plugin to the `[project]/android/app/build.gradle` file. | ||||||
| ```gradle | ||||||
| // ADD THIS AT THE BOTTOM | ||||||
| apply plugin: 'com.google.gms.google-services' | ||||||
| ``` | ||||||
|
|
||||||
| *Note:* If this section is not completed you will get an error like this: | ||||||
| ``` | ||||||
| java.lang.IllegalStateException: | ||||||
| Default FirebaseApp is not initialized in this process [package name]. | ||||||
| Make sure to call FirebaseApp.initializeApp(Context) first. | ||||||
| ``` | ||||||
|
|
||||||
| *Note:* When you are debugging on android, use a device or AVD with Google Play services. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
| Otherwise you will not be able to use Firebase In-App Messaging. | ||||||
|
|
||||||
| ### Use the plugin | ||||||
|
|
||||||
| To show In-App Messages in your app, no extra setup is required - just import the plugin and you | ||||||
| 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 - | ||||||
|
|
||||||
| First off, add the following imports to your Dart code: | ||||||
| ```dart | ||||||
| import 'package:firebase_inappmessaging/firebase_inappmessaging.dart'; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||
| ``` | ||||||
|
|
||||||
| #### Programmatic Triggers ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#trigger_in-app_messages_programmatically)) | ||||||
|
|
||||||
| To trigger in-app messages programmatically | ||||||
|
|
||||||
| ```dart | ||||||
| FirebaseInAppMessaging.triggerEvent('eventName'); | ||||||
| ``` | ||||||
|
|
||||||
| #### Temporarily disable in-app messages ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#temporarily_disable_in-app_messages)) | ||||||
|
|
||||||
| 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 | ||||||
|
|
||||||
| ```dart | ||||||
| FirebaseInAppMessaging.setMessagesSuppressed(true); | ||||||
|
|
||||||
|
|
||||||
| // To re-enable | ||||||
| FirebaseInAppMessaging.setMessagesSuppressed(false); | ||||||
| ``` | ||||||
|
|
||||||
| #### Enable opt-out message delivery ([docs](https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=android#enable_opt-out_message_delivery)) | ||||||
|
|
||||||
| 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: | ||||||
|
|
||||||
| ```dart | ||||||
| FirebaseInAppMessaging.setAutomaticDataCollectionEnabled(false); | ||||||
| ``` | ||||||
|
|
||||||
| ## Example | ||||||
|
|
||||||
| See the [example application](https://github.com/flutter/plugins/tree/master/packages/firebase_inappmessaging/example) source | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
| for a complete sample app using the Firebase In-App Messaging. | ||||||
|
|
||||||
| ## Issues and feedback | ||||||
|
|
||||||
| Please file [issues](https://github.com/flutter/flutter/issues/new) | ||||||
| to send feedback or report a bug. Thank you! | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| *.iml | ||
| .gradle | ||
| /local.properties | ||
| /.idea/workspace.xml | ||
| /.idea/libraries | ||
| .DS_Store | ||
| /build | ||
| /captures |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| group 'com.example.firebase_in_app_messaging' | ||
| version '1.0-SNAPSHOT' | ||
|
|
||
| buildscript { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
|
|
||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:3.3.0' | ||
| } | ||
| } | ||
|
|
||
| rootProject.allprojects { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
| } | ||
|
|
||
| apply plugin: 'com.android.library' | ||
|
|
||
| android { | ||
| compileSdkVersion 28 | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion 16 | ||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
| lintOptions { | ||
| disable 'InvalidPackage' | ||
| } | ||
| dependencies { | ||
| api 'com.google.firebase:firebase-inappmessaging-display:18.0.1' | ||
| implementation 'androidx.annotation:annotation:1.0.0' | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| org.gradle.jvmargs=-Xmx1536M | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rootProject.name = 'firebase_in_app_messaging' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.example.firebase_in_app_messaging"> | ||
| </manifest> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||
| package com.example.firebase_in_app_messaging; | ||||||
|
|
||||||
| import com.google.firebase.inappmessaging.FirebaseInAppMessaging; | ||||||
| import io.flutter.plugin.common.MethodCall; | ||||||
| import io.flutter.plugin.common.MethodChannel; | ||||||
| import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||||||
| import io.flutter.plugin.common.MethodChannel.Result; | ||||||
| import io.flutter.plugin.common.PluginRegistry.Registrar; | ||||||
|
|
||||||
| /** FirebaseInAppMessagingPlugin */ | ||||||
| public class FirebaseInAppMessagingPlugin implements MethodCallHandler { | ||||||
| private final FirebaseInAppMessaging instance; | ||||||
|
|
||||||
| public static void registerWith(Registrar registrar) { | ||||||
| final MethodChannel channel = | ||||||
| new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_inappmessaging"); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
| channel.setMethodCallHandler(new FirebaseInAppMessagingPlugin()); | ||||||
| } | ||||||
|
|
||||||
| private FirebaseInAppMessagingPlugin() { | ||||||
| instance = FirebaseInAppMessaging.getInstance(); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void onMethodCall(MethodCall call, Result result) { | ||||||
| switch (call.method) { | ||||||
| case "triggerEvent": | ||||||
| { | ||||||
| String eventName = call.argument("eventName"); | ||||||
| instance.triggerEvent(eventName); | ||||||
| result.success(null); | ||||||
| break; | ||||||
| } | ||||||
| case "setMessagesSuppressed": | ||||||
| { | ||||||
| Boolean suppress = (Boolean) call.arguments; | ||||||
| instance.setMessagesSuppressed(suppress); | ||||||
| result.success(null); | ||||||
| break; | ||||||
| } | ||||||
| case "setAutomaticDataCollectionEnabled": | ||||||
| { | ||||||
| Boolean enabled = (Boolean) call.arguments; | ||||||
| instance.setAutomaticDataCollectionEnabled(enabled); | ||||||
| result.success(null); | ||||||
| break; | ||||||
| } | ||||||
| default: | ||||||
| { | ||||||
| result.notImplemented(); | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Miscellaneous | ||
| *.class | ||
| *.log | ||
| *.pyc | ||
| *.swp | ||
| .DS_Store | ||
| .atom/ | ||
| .buildlog/ | ||
| .history | ||
| .svn/ | ||
|
|
||
| # IntelliJ related | ||
| *.iml | ||
| *.ipr | ||
| *.iws | ||
| .idea/ | ||
|
|
||
| # The .vscode folder contains launch configuration and tasks you configure in | ||
| # VS Code which you may wish to be included in version control, so this line | ||
| # is commented out by default. | ||
| #.vscode/ | ||
|
|
||
| # Flutter/Dart/Pub related | ||
| **/doc/api/ | ||
| .dart_tool/ | ||
| .flutter-plugins | ||
| .packages | ||
| .pub-cache/ | ||
| .pub/ | ||
| /build/ | ||
|
|
||
| # Android related | ||
| **/android/**/gradle-wrapper.jar | ||
| **/android/.gradle | ||
| **/android/captures/ | ||
| **/android/gradlew | ||
| **/android/gradlew.bat | ||
| **/android/local.properties | ||
| **/android/**/GeneratedPluginRegistrant.java | ||
|
|
||
| # iOS/XCode related | ||
| **/ios/**/*.mode1v3 | ||
| **/ios/**/*.mode2v3 | ||
| **/ios/**/*.moved-aside | ||
| **/ios/**/*.pbxuser | ||
| **/ios/**/*.perspectivev3 | ||
| **/ios/**/*sync/ | ||
| **/ios/**/.sconsign.dblite | ||
| **/ios/**/.tags* | ||
| **/ios/**/.vagrant/ | ||
| **/ios/**/DerivedData/ | ||
| **/ios/**/Icon? | ||
| **/ios/**/Pods/ | ||
| **/ios/**/.symlinks/ | ||
| **/ios/**/profile | ||
| **/ios/**/xcuserdata | ||
| **/ios/.generated/ | ||
| **/ios/Flutter/App.framework | ||
| **/ios/Flutter/Flutter.framework | ||
| **/ios/Flutter/Generated.xcconfig | ||
| **/ios/Flutter/app.flx | ||
| **/ios/Flutter/app.zip | ||
| **/ios/Flutter/flutter_assets/ | ||
| **/ios/ServiceDefinitions.json | ||
| **/ios/Runner/GeneratedPluginRegistrant.* | ||
|
|
||
| # Exceptions to above rules. | ||
| !**/ios/**/default.mode1v3 | ||
| !**/ios/**/default.mode2v3 | ||
| !**/ios/**/default.pbxuser | ||
| !**/ios/**/default.perspectivev3 | ||
| !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file tracks properties of this Flutter project. | ||
| # Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| # | ||
| # This file should be version controlled and should not be manually edited. | ||
|
|
||
| version: | ||
| revision: 2e540931f73593e35627592ca4f9a4ca3035ed31 | ||
| channel: stable | ||
|
|
||
| project_type: app |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # firebase_in_app_messaging_example | ||
|
|
||
| Demonstrates how to use the firebase_in_app_messaging plugin. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| This project is a starting point for a Flutter application. | ||
|
|
||
| A few resources to get you started if this is your first Flutter project: | ||
|
|
||
| - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) | ||
| - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) | ||
|
|
||
| For help getting started with Flutter, view our | ||
| [online documentation](https://flutter.dev/docs), which offers tutorials, | ||
| samples, guidance on mobile development, and a full API reference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.