[firebase_in_app_messaging] add new plugin#1791
[firebase_in_app_messaging] add new plugin#1791collinjackson merged 18 commits intoflutter:masterfrom prakhar1989:inappmessaging-plugin
Conversation
collinjackson
left a comment
There was a problem hiding this comment.
Thanks for the PR -- this is a great start.
I made some high-level comments on the Dart API. If those sound reasonable let me know when they're addressed and I'll re-review.
It doesn't seem like the integration tests are going to be easy but we should have unit tests at least.
| const MethodChannel channel = MethodChannel('firebase_inappmessaging'); | ||
|
|
||
| setUp(() { | ||
| channel.setMockMethodCallHandler((MethodCall methodCall) async { |
There was a problem hiding this comment.
Can you please add unit tests following the pattern of other plugins?
There was a problem hiding this comment.
done - let me know what you think!
packages/firebase_inappmessaging/lib/firebase_inappmessaging.dart
Outdated
Show resolved
Hide resolved
packages/firebase_inappmessaging/lib/firebase_inappmessaging.dart
Outdated
Show resolved
Hide resolved
packages/firebase_inappmessaging/lib/firebase_inappmessaging.dart
Outdated
Show resolved
Hide resolved
packages/firebase_inappmessaging/lib/firebase_inappmessaging.dart
Outdated
Show resolved
Hide resolved
|
Oh hey, I was interested in this! Though it kind of slipped through the cracks what with work and all I think one of the big things people would want from this plugin would be the ability to receive messages in Dart (so they can e.g. be rendered as widgets)? Basically to gain the full range of functionality described in the docs. I am not quite sure what an API that accommodates that would look like though. |
I agree. It would be great to have that functionality. |
I agree - that'd be a nice feature to have! However, the current In-App Messaging SDK doesn't export the message that's about to be displayed. The only way to customize the messages outside of what the Firebase Console provides would be via forking the SDK as documented here. As this plugin uses the published In-App Messaging SDKs I don't think its possible to provide message customization via Dart Widgets until the underlying SDK supports that functionality. |
Forking the SDK isn't the only way to customize messages - it's pretty much a matter of changing the Fully customizable messages are definitely a nice-to-have though, at this point what I'd say is much more critical is support for event listeners (sending messages to your users isn't very useful when you can't access their response 😅) |
collinjackson
left a comment
There was a problem hiding this comment.
Thanks, this is looking good. Sorry for not catching this earlier, but I think you should replace firebase_inappmessaging with firebase_in_app_messaging for consistency with other Flutterfire plugins such remote_config.
| import io.flutter.plugin.common.PluginRegistry.Registrar; | ||
|
|
||
| /** FirebaseInappmessagingPlugin */ | ||
| public class FirebaseInappmessagingPlugin implements MethodCallHandler { |
There was a problem hiding this comment.
In think this should be FirebaseInAppMessagingPlugin
| result.success(null); | ||
| break; | ||
| } | ||
| case "dataCollectionEnabled": |
There was a problem hiding this comment.
I would call this setAutomaticDataCollectionEnabled, otherwise it looks like a getter. And "automatic" in the name is consistent across iOS and Android.
There was a problem hiding this comment.
Great call - done!
|
|
||
| #import <Firebase/Firebase.h> | ||
|
|
||
| @implementation FirebaseInappmessagingPlugin |
There was a problem hiding this comment.
I would capitalize FirebaseInAppMessagingPlugin
| # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html | ||
| # | ||
| Pod::Spec.new do |s| | ||
| s.name = 'firebase_inappmessaging' |
There was a problem hiding this comment.
firebase_in_app_messaging
| Pod::Spec.new do |s| | ||
| s.name = 'firebase_inappmessaging' | ||
| s.version = '0.0.1' | ||
| s.summary = 'Firebase InAppMessaging Plugin for Firebase' |
There was a problem hiding this comment.
This is redundant, maybe "In-app messaging plugin for Firebase"
| @@ -0,0 +1,25 @@ | |||
| name: firebase_inappmessaging | |||
There was a problem hiding this comment.
firebase_in_app_messaging
|
|
||
| flutter: | ||
| plugin: | ||
| androidPackage: com.example.firebase_inappmessaging |
There was a problem hiding this comment.
firebase_in_app_messaging
| @@ -0,0 +1,3 @@ | |||
| ## 0.0.1 | |||
|
|
|||
| * TODO: Describe initial release. | |||
There was a problem hiding this comment.
| * TODO: Describe initial release. | |
| * Initial release. |
| @@ -0,0 +1,90 @@ | |||
| # firebase_inappmessaging plugin | |||
There was a problem hiding this comment.
| # firebase_inappmessaging plugin | |
| # firebase_in_app_messaging plugin |
|
|
||
| ## Usage | ||
|
|
||
| ### Import the firebase_inappmessaging plugin |
There was a problem hiding this comment.
| ### Import the firebase_inappmessaging plugin | |
| ### Import the firebase_in_app_messaging plugin |
| ## 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). |
There was a problem hiding this comment.
| To use the firebase_inappmessaging plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_inappmessaging#pub-pkg-tab-installing). | |
| To use the firebase_in_app_messaging plugin, follow the [plugin installation instructions](https://pub.dartlang.org/packages/firebase_inappmessaging#pub-pkg-tab-installing). |
|
|
||
| First off, add the following imports to your Dart code: | ||
| ```dart | ||
| import 'package:firebase_inappmessaging/firebase_inappmessaging.dart'; |
There was a problem hiding this comment.
| import 'package:firebase_inappmessaging/firebase_inappmessaging.dart'; | |
| import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart'; |
|
|
||
| test('triggerEvent', () async { | ||
| final FirebaseInAppMessaging fiam = FirebaseInAppMessaging(); | ||
| fiam.triggerEvent('someEvent'); |
There was a problem hiding this comment.
Generally I think we should await async methods in tests to ensure success and prevent race conditions.
| const SizedBox(height: 8), | ||
| RaisedButton( | ||
| onPressed: () async { | ||
| await fiam.triggerEvent('chicken_event'); |
There was a problem hiding this comment.
Is awaiting the event really necessary here? If calling await isn't something we want developers to feel obligated to do, then perhaps we should have onPressed be synchronous here and just fire and forget triggerEvent. There doesn't seem to be any error handling on the native side, so triggerEvent is unlikely to fail, and I think the Future error handling is mostly just for use in tests.
There was a problem hiding this comment.
Good call - done!
| class MyApp extends StatelessWidget { | ||
| static FirebaseAnalytics analytics = FirebaseAnalytics(); | ||
| static FirebaseAnalyticsObserver observer = | ||
| FirebaseAnalyticsObserver(analytics: analytics); |
There was a problem hiding this comment.
It doesn't seem like you're doing anything with observer here. In order for the observer to be useful you have to pass it to the navigatorObservers of MaterialApp.
There was a problem hiding this comment.
Nice catch - removed it.
| @@ -0,0 +1,122 @@ | |||
| import 'dart:async'; | |||
|
|
|||
| import 'package:firebase_analytics/firebase_analytics.dart'; | |||
There was a problem hiding this comment.
I think we should simplify the example to focus on firebase_in_app_messaging and not include the analytics stuff. To reduce maintenance overhead, plugins should try to avoid unnecessary dependencies on other plugins, even in the examples, unless the other plugins are really necessary to understand how the plugin works. Sometimes it's not possible (e.g. firebase_database, firebase_auth) but here it doesn't seem like there's much interaction going on between analytics and fiam here. Let me know if you feel otherwise...
There was a problem hiding this comment.
Hmm, I think having the analytics trigger is a good idea. It's something users ask us about and the example shows doing that in Flutter is equally easy. So I think it's nice to keep since it doesn't add much complexity to the already straightforward example.
There was a problem hiding this comment.
OK, we can leave it there for now but we might remove it in a future release.
| Make sure to call FirebaseApp.initializeApp(Context) first. | ||
| ``` | ||
|
|
||
| *Note:* When you are debugging on android, use a device or AVD with Google Play services. |
There was a problem hiding this comment.
| *Note:* When you are debugging on android, use a device or AVD with Google Play services. | |
| *Note:* When you are debugging on Android, use a device or AVD with Google Play services. |
| @@ -0,0 +1,122 @@ | |||
| import 'dart:async'; | |||
|
|
|||
| import 'package:firebase_analytics/firebase_analytics.dart'; | |||
There was a problem hiding this comment.
OK, we can leave it there for now but we might remove it in a future release.
* add plugin for firebase inappmessaging
Description
Add a new plugin for Firebase In-App Messaging
Related Issues
None
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?