OneSignal/OneSignal-Flutter-SDK

[Bug]: OneSignal.Notifications.addClickListener getting called as many times as app gets hot restarted

AchmadSyarippudin opened this issue · 1 comments

What happened?

I want navigate to specific page when notification was click.

so I added this code :

"OneSignal.Notifications.addClickListener((OSNotificationClickEvent event) {
print(event.notification.additionalData);
})"

Steps to reproduce?

1. onesignal Version 5.2 
2. Degugging on android emulator 
3. add this code "OneSignal.Notifications.addClickListener((OSNotificationClickEvent event) {
      print(event.notification.additionalData);
    });"
4. restart /  hot reload application
5. check console log data was print as many times as app gets hot restarted

What did you expect to happen?

my expectation "print" only appears when I was clicked notification.

OneSignal Flutter SDK version

5.2.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Code : 

 @override
  void initState() {
    //--- notification
    OneSignal.Debug.setLogLevel(OSLogLevel.error);
    OneSignal.initialize(Environment.oneSignalAppID);
    OneSignal.Notifications.requestPermission(true);
    OneSignal.Notifications.addClickListener((OSNotificationClickEvent event) {
      print(event.notification.additionalData);
    });
    super.initState();
  } 

Log : 
7
I/flutter (13699): {action_url: /order/detail?id=1032, icon: asset/Icons/2024-04-22-10512396440.png, description: Pembayaran tagihan BPJS Kesehatan 1 bulan : BERHASIL, title: Transaksi BPJS Kesehatan Berhasil, type: notif, category: BPJS Kesehatan, status: unread}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Closing as this is same issue as #763 where it is being discussed