Skip to content

onPushNotification just fires on iOS not on Android #81

@Oni22

Description

@Oni22

Checklist

  • I have determined whether this bug is also reproducible in a vanilla project, such as the example app in this repository.
  • If possible, I've reproduced the issue using the master branch or latest release of this package.
  • This issue hasn't been addressed in an existing issue or pull request

Description

First of all, thanks for the great package and the work on the Flutter SDK.

I noticed an inconsistency in the behavior of the KlaviyoSDK().onPushNotification listener between iOS and Android.

Current Behavior

iOS

KlaviyoSDK().onPushNotification is triggered as expected for Klaviyo push notifications.

Android

KlaviyoSDK().onPushNotification is never triggered. Instead, all incoming messages (including Klaviyo messages) are only received through:

  • FirebaseMessaging.onMessage
  • FirebaseMessaging.onMessageOpenedApp

This means on Android I need to manually detect whether a message is from Klaviyo and handle it inside the Firebase listeners, while on iOS I handle Klaviyo notifications through onPushNotification.

Expected Behavior

Ideally, KlaviyoSDK().onPushNotification should behave consistently across both platforms, or the platform-specific behavior should be clearly documented.

Question

Is this intended behavior on Android?

If yes, it would be very helpful to mention this difference explicitly in the documentation, since currently it seems like the listener should work the same way on both platforms.

Example

if (Platform.isAndroid) {
  FirebaseMessaging.onMessage.listen((message) {
    if (message.data.isKlaviyoNotification) {
      // Handle Klaviyo notification manually
    } else {
      // Handle regular Firebase notification
    }
  });

  FirebaseMessaging.onMessageOpenedApp.listen((message) {
    // Handle opened notification
  });
} else if (Platform.isIOS) {
  KlaviyoSDK().onPushNotification.listen((event) {
    if (event['type'] == 'push_notification_opened') {
      // Handle opened notification
    }
  });
}

Additional Context

Because of this difference, notification handling logic needs to be split by platform, which adds extra complexity in cross-platform Flutter apps.


### Expected behavior

```markdown
KlaviyoSDK().onPushNotification.listen should handle messages on both platforms

Actual behavior

KlaviyoSDK().onPushNotification.listen just works on iOS

Steps to reproduce

Send message through firebase and klaviyo on android and then ios

The Klaviyo Flutter SDK version information

0.1.0

Flutter and Dart version

Flutter 3.38.4, Dart 3.10.3

Device and OS information

Nothing Phone, Iphone 14 Pro Max

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions