0

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
  • 43
  • 1
  • 9

1 Answers1

1

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

Ananda Pramono
  • 899
  • 1
  • 6
  • 18
  • 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. – Ajay Kumar Oct 07 '21 at 06:34
  • Oh sorry about it. You can try this, maybe it will help in some ways. https://stackoverflow.com/questions/57650892/flutter-how-to-do-a-task-after-user-open-push-notif-message-fcm – Ananda Pramono Oct 07 '21 at 07:16
  • @AnandaPramono did u got solution for your post? – Subhangi Pawar Feb 20 '23 at 15:45