Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[firebase_in_app_messaging] add new plugin #1791

Merged
merged 18 commits into from
Jul 18, 2019
Merged

[firebase_in_app_messaging] add new plugin #1791

merged 18 commits into from
Jul 18, 2019

Conversation

prakhar1989
Copy link
Contributor

@prakhar1989 prakhar1989 commented Jul 2, 2019

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@collinjackson collinjackson self-requested a review July 3, 2019 00:01
Copy link
Contributor

@collinjackson collinjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add unit tests following the pattern of other plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - let me know what you think!

@filleduchaos
Copy link
Contributor

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.

@collinjackson
Copy link
Contributor

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.

@prakhar1989
Copy link
Contributor Author

prakhar1989 commented Jul 8, 2019

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 - 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.

@filleduchaos
Copy link
Contributor

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 - 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 messageDisplayComponent from the default InAppMessagingDisplay (see Android and iOS). Admittedly that's less straightforward on iOS; the iOS SDK seems pretty strict about having to use the headless flavour if you want to override the message display, but I've never actually tried doing that with the full one.

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 😅)

Copy link
Contributor

@collinjackson collinjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

result.success(null);
break;
}
case "dataCollectionEnabled":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this setAutomaticDataCollectionEnabled, otherwise it looks like a getter. And "automatic" in the name is consistent across iOS and Android.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call - done!


#import <Firebase/Firebase.h>

@implementation FirebaseInappmessagingPlugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would capitalize FirebaseInAppMessagingPlugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'firebase_inappmessaging'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firebase_in_app_messaging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Pod::Spec.new do |s|
s.name = 'firebase_inappmessaging'
s.version = '0.0.1'
s.summary = 'Firebase InAppMessaging Plugin for Firebase'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant, maybe "In-app messaging plugin for Firebase"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,25 @@
name: firebase_inappmessaging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firebase_in_app_messaging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


flutter:
plugin:
androidPackage: com.example.firebase_inappmessaging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firebase_in_app_messaging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@collinjackson collinjackson changed the title [firebase_inappmessaging] add new plugin [firebase_in_app_messaging] add new plugin Jul 17, 2019
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* TODO: Describe initial release.
* Initial release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,90 @@
# firebase_inappmessaging plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# firebase_inappmessaging plugin
# firebase_in_app_messaging plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


## Usage

### Import the firebase_inappmessaging plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Import the firebase_inappmessaging plugin
### Import the firebase_in_app_messaging plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

## 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


First off, add the following imports to your Dart code:
```dart
import 'package:firebase_inappmessaging/firebase_inappmessaging.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import 'package:firebase_inappmessaging/firebase_inappmessaging.dart';
import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


test('triggerEvent', () async {
final FirebaseInAppMessaging fiam = FirebaseInAppMessaging();
fiam.triggerEvent('someEvent');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I think we should await async methods in tests to ensure success and prevent race conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const SizedBox(height: 8),
RaisedButton(
onPressed: () async {
await fiam.triggerEvent('chicken_event');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - done!

class MyApp extends StatelessWidget {
static FirebaseAnalytics analytics = FirebaseAnalytics();
static FirebaseAnalyticsObserver observer =
FirebaseAnalyticsObserver(analytics: analytics);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch - removed it.

@@ -0,0 +1,122 @@
import 'dart:async';

import 'package:firebase_analytics/firebase_analytics.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@collinjackson collinjackson self-assigned this Jul 17, 2019
@@ -0,0 +1,122 @@
import 'dart:async';

import 'package:firebase_analytics/firebase_analytics.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we can leave it there for now but we might remove it in a future release.

@collinjackson collinjackson merged commit 990bba9 into flutter:master Jul 18, 2019
@prakhar1989 prakhar1989 deleted the inappmessaging-plugin branch July 18, 2019 22:57
mithun-mondal pushed a commit to bKash-developer/archived_plugins that referenced this pull request Aug 6, 2019
* add plugin for firebase inappmessaging
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants