Search code examples
flutterdartonesignal

How can I set setNotificationOpenedHandler method in flutter app?


In order to use push notification I used onesignal.When user taps the notification,It should navigate to screen.For doing it I need setNotificationOpenedHandler method.However it is missing.I can see OneSignal.Notifications.addForegroundWillDisplayListener((event) { }) method but not

OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
    print('"OneSignal: notification opened: ${result}');
});

method

I read the onesignal documentation but there is no special info about it.


Solution

  •     ///
        /// This will be called when a notification is received while the app is open.
        /// This code works only -onesignal_flutter: ^5.0.2
        /// You can use that then OneSignal initialized
    
        OneSignal.Notifications.addClickListener((event) {
          debugPrint("Notification Clicked: $event");
          
        });