This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[firebase_in_app_messaging] add new plugin #1791
Merged
collinjackson
merged 18 commits into
flutter-team-archive:master
from
prakhar1989:inappmessaging-plugin
Jul 18, 2019
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6127d09
add plugin for firebase inappmessaging
prakhar1989 3c46be0
address comments
prakhar1989 d5ceda4
Fix dart analyze issues
prakhar1989 a61554b
use instance methods instead of static
prakhar1989 37fb5f7
add unit test for the plugin
prakhar1989 da2c34d
run dart formatter
prakhar1989 82f41f8
fix formatting
prakhar1989 3a89c02
fix pubspec.yaml
prakhar1989 8d810d3
fix analyze issues
prakhar1989 2d8f9a9
more analyze fixes
prakhar1989 d507113
uhhh formatting
prakhar1989 ee0ea7a
s/firebase_inappmessaging/firebase_in_app_messaging
prakhar1989 7c82b7f
change method name to setAutomaticDataCollectionEnabled
prakhar1989 1bce955
reformatting
prakhar1989 64eb8a7
add test_driver and change call arguments
prakhar1989 1a769fc
remove useless comments
prakhar1989 d71ff60
action feedback
prakhar1989 00fee03
clean up readme in example project
prakhar1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| .DS_Store | ||
| .dart_tool/ | ||
|
|
||
| .packages | ||
| .pub/ | ||
|
|
||
| build/ | ||
| .DS_Store | ||
| .atom/ | ||
| .idea/ | ||
| .vscode/ | ||
|
|
||
| .packages | ||
| .pub/ | ||
| .dart_tool/ | ||
| pubspec.lock | ||
|
|
||
| Podfile | ||
| Podfile.lock | ||
| Pods/ | ||
| .symlinks/ | ||
| **/Flutter/App.framework/ | ||
| **/Flutter/Flutter.framework/ | ||
| **/Flutter/Generated.xcconfig | ||
| **/Flutter/flutter_assets/ | ||
| ServiceDefinitions.json | ||
| xcuserdata/ | ||
| *.xcworkspace | ||
|
|
||
| local.properties | ||
| keystore.properties | ||
| .gradle/ | ||
| gradlew | ||
| gradlew.bat | ||
| gradle-wrapper.jar | ||
| *.iml | ||
|
|
||
| GeneratedPluginRegistrant.h | ||
| GeneratedPluginRegistrant.m | ||
| GeneratedPluginRegistrant.java | ||
| build/ | ||
| .flutter-plugins | ||
|
|
||
| .xcconfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: bc7bc940836f1f834699625426795fd6f07c18ec | ||
| channel: beta | ||
|
|
||
| project_type: plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## 0.0.1 | ||
|
|
||
| * Implement Firebase In-App Messaging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # firebase_inappmessaging plugin | ||
|
|
||
| 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 | ||
| To use the firebase_inappmessaging plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_inappmessaging#pub-pkg-tab-installing). | ||
|
|
||
| ### 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. | ||
| 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'; | ||
| ``` | ||
|
|
||
| #### 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.dataCollectionEnabled(false); | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| See the [example application](https://github.com/flutter/plugins/tree/master/packages/firebase_inappmessaging/example) source | ||
| 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| group 'com.example.firebase_inappmessaging' | ||
| 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' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.gradle.jvmargs=-Xmx1536M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rootProject.name = 'firebase_inappmessaging' |
3 changes: 3 additions & 0 deletions
3
packages/firebase_inappmessaging/android/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_inappmessaging"> | ||
| </manifest> |
56 changes: 56 additions & 0 deletions
56
...droid/src/main/java/com/example/firebase_inappmessaging/FirebaseInappmessagingPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.example.firebase_inappmessaging; | ||
|
|
||
| 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"); | ||
| 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 = call.argument("suppress"); | ||
| instance.setMessagesSuppressed(suppress); | ||
| result.success(null); | ||
| break; | ||
| } | ||
| case "dataCollectionEnabled": | ||
|
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. I would call this
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. Great call - done! |
||
| { | ||
| boolean dataCollectionEnabled = call.argument("dataCollectionEnabled"); | ||
| instance.setAutomaticDataCollectionEnabled(dataCollectionEnabled); | ||
| result.success(null); | ||
| break; | ||
| } | ||
| default: | ||
| { | ||
| result.notImplemented(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: bc7bc940836f1f834699625426795fd6f07c18ec | ||
| channel: beta | ||
|
|
||
| project_type: app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # firebase_inappmessaging_example | ||
|
|
||
| Demonstrates how to use the firebase_inappmessaging plugin. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| For help getting started with Flutter, view our online | ||
| [documentation](http://flutter.io/). | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In think this should be FirebaseInAppMessagingPlugin
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.