본문 바로가기
개발/Flutter

Flutter -When FirebaseMessaging.onMessageOpenedApp.listen is not triggered

by dev_caleb 2022. 2. 3.
728x90

I used flutter with FCM and i found FirebaseMessaging.onMessageOpenedApp.listen is only worked app is not terminated. 
I seached stackoverflow and i found the answer. 

 

The full story is below.

https://stackoverflow.com/questions/68119898/flutter-firebasemessaging-onmessageopenedapp-listen-is-not-triggered

 

Flutter - FirebaseMessaging.onMessageOpenedApp.listen is not triggered

I am using: flutter version 2.2 firebase_messaging: ^10.0.2 I receive push notification, then click on it and the app is opened. Then I do not see FirebaseMessaging.onMessageOpenedApp.listen gett...

stackoverflow.com

 

 

 

 

For the first question:

To view the logs from your app, you can use the 'Logcat' tab in Android Studio or IntelliJ: 

For the second question:

If your app is terminated and you want to receive a notification click callback, you should use:

FirebaseMessaging.instance.getInitialMessage().then((message) {
  if (message != null) {
    // DO YOUR THING HERE
  }
});

, because according to the Flutter team's comments for onMessageopenedApp function:

 /// If your app is opened via a notification whilst the app is terminated,
  /// see [getInitialMessage].

 

728x90