Skip to content

[firebase_messaging] functions are not triggered inside notification callback #3781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
apoleo88 opened this issue Oct 5, 2020 · 8 comments · Fixed by #4012
Closed

[firebase_messaging] functions are not triggered inside notification callback #3781

apoleo88 opened this issue Oct 5, 2020 · 8 comments · Fixed by #4012
Labels
plugin: messaging type: question A question where further information is requested

Comments

@apoleo88
Copy link

apoleo88 commented Oct 5, 2020

When a notification arrives, it triggers correctly onMessage(and the others), but it doesn't trigger the function call inside it.

_fcm.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message"); // this is printed
        // static function:
        thisWeirdNotification(message['data']); // this is not called
      },
      ...
)
onMessage: {
  notification: {title: "yeaah", body: null},
  data: {channel_id: "chanel-name", info: "1", click_action: FLUTTER_NOTIFICATION_CLICK}
}
[√] Flutter (Channel master, 1.23.0-8.0.pre.124, on Microsoft Windows [Versione 10.0.19041.508], locale it-IT)
    • Flutter version 1.23.0-8.0.pre.124 at C:\src\flutter
    • Framework revision cbf1e135c4 (3 days ago), 2020-10-02 21:57:04 -0700
    • Engine revision 87a10f240f
    • Dart version 2.11.0 (build 2.11.0-181.0.dev)


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at C:\Users\_Apoleo\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: C:\Users\_Apoleo\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\193.6626763\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at C:\Users\_Apoleo\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\193.6626763
    • Flutter plugin version 47.1.1
    • Dart plugin version 192.8052
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

• No issues found!

I am not sure what's happening because the execution truncates without errors, is it suppressing one?

@masterplox
Copy link

masterplox commented Oct 6, 2020

Is it possible that thisWeirdNotification() is also an async method. Meaning, you'd need to call await thisWeirdNotification() instead?

I've ran into this problem before and that was my mistake, not putting that await keyword before my async method names.

@apoleo88
Copy link
Author

apoleo88 commented Oct 6, 2020

Yes, it is async, but but the await doesn't solve the issue.

I found the error, it is a data type one.
The parameter sent message['data'] was a LinkedHashMap<dynamic, dynamic> type, but my function accepted a Map<String, dynamic>.

thisWeirdNotification(Map<String, dynamic> data) async{...}

So, I guess that somehow the error is been suppressed!

@masterplox
Copy link

I've found that what helps me to debug is to put everything that is bound to have some sort of logic that can cause errors, in a try/catch block. Then debugPrinting out the catch exception. Then placing my breakpoint where I wrote that line to print. e.g

try {
    ///Some weird logic
}catch(e){
    debugPrint(e.toString()); 
}

It could help you to find future errors like these. And honestly, ever since I moved to JsonSerializable, errors like that haven't gotten to me.

@apoleo88
Copy link
Author

apoleo88 commented Oct 6, 2020

Yep, like that the error comes out:
I/flutter (27070): type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>'

@darshankawar
Copy link

@apoleo88
It seems your original issue has been resolved. Can this issue be closed ?
Thanks.

@darshankawar darshankawar added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Oct 7, 2020
@apoleo88
Copy link
Author

apoleo88 commented Oct 7, 2020

@apoleo88
It seems your original issue has been resolved. Can this issue be closed ?
Thanks.

My issue is solved, but it is not clear to me why the debug error is been surpressed.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Oct 7, 2020
@darshankawar darshankawar added plugin: messaging type: question A question where further information is requested and removed Needs Attention This issue needs maintainer attention. labels Oct 13, 2020
@p02diada
Copy link

I have the same problem, it's very hard to debug a callback error

@thesmalleyes
Copy link

I have the same problem, because I added

<service
     android:name="com.clevertap.android.sdk.pushnotification.fcm.FcmMessageListenerService">
     <intent-filter>
           <action android:name="com.google.firebase.MESSAGING_EVENT"/>
     </intent-filter>
</service>

But I need to add this service, because of the clevertap plugin needs it to render the notification. Is there any way to merge this service and FCM flutter who does not need this?

@firebase firebase locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: messaging type: question A question where further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants