Flutter FCM push notification - Foreground Notification tap event

849

You can try this, hope its help you:

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  print('Got a message whilst in the foreground!');
  print('Message data: ${message.data}');

  if (message.notification != null) {
    print('Message also contained a notification: ${message.notification}');
  }
});

I copy that code from the Flutter Fire documentation, I will put the link here https://firebase.flutter.dev/docs/messaging/usage

Share:
849
Ajay Kumar
Author by

Ajay Kumar

Updated on January 01, 2023

Comments

  • Ajay Kumar
    Ajay Kumar over 1 year

    Am using firebase_messaging and flutter_local_notifications packages, Currently am able to get the notification data when the user tap the notification when the app is in the background. How can i listen to the tap event when the app is in the foreground.

  • Ajay Kumar
    Ajay Kumar over 2 years
    Hi @Ananda thanks for the answer but this event is triggered when a notification is received but i need it when the user tap the notification.
  • Ananda Pramono
    Ananda Pramono over 2 years
    Oh sorry about it. You can try this, maybe it will help in some ways. stackoverflow.com/questions/57650892/…