Skip to content

🐛 [Firebase_messaging] OnMessage and OnMessageOpenedApp not handling events #5324

Closed
@santiotin

Description

@santiotin

Bug report

I have an app that was using firebase messaging 7.0.3 and all worked perfectly. But when I migrated to firebase messaging 9.0.0, the push notifications are not being handled.

I know that the app is correctly linked to firebase and cloud messaging because when app is in background I see the push notification in the phone, the problem is when I click that notification the app don't handle this event. Also, when the app is in foreground, the event of receiving the notification is not being triggered.

Specifically, the functions FirebaseMessaging.onMessage and FirebaseMessaging.onMessageOpenedApp are the ones not triggered. My code is:

FirebaseMessaging.onMessage.listen((RemoteMessage message) { print("notif: message"); }); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { print("notif: resume"); });

The prints are never called, and if I put some more code inside isn't executed too.

I also call getToken and I can get the token, plus when the app is in background I see the push notification, so is not a link problem with firebase. In the logs, when I receive the push I can see a message saying:

"D/FLTFireMsgReceiver(20634): broadcast received for message".

Before running the app, I also await to Firebase initialization, so this is not the problem.
WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp();

So I assumed that the push is arriving in all the occasions, and I am doing something wrong in the code. I tested all cases in Android and iOS physical devices.

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel stable, 2.0.0, on Mac OS X 10.15.7 19H524 darwin-x64, locale es-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.54.2)
[✓] Connected device (2 available)

• No issues found!

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.12.0
Flutter SDK 2.0.0
binapp 1.0.0+1

dependencies:
- bloc 7.0.0-nullsafety.3 [meta]
- camera 0.8.0 [flutter camera_platform_interface pedantic quiver]
- cloud_firestore 1.0.0 [cloud_firestore_platform_interface cloud_firestore_web firebase_core firebase_core_platform_interface flutter meta]
- cupertino_icons 1.0.0
- diacritic 0.1.3
- equatable 2.0.0 [collection meta]
- firebase_auth 1.0.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.0.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 9.0.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 8.0.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_barcode_scanner 2.0.0-nullsafety.0 [flutter flutter_plugin_android_lifecycle]
- flutter_bloc 7.0.0-nullsafety.3 [flutter bloc provider]
- flutter_cupertino_localizations 1.0.1 [flutter flutter_localizations]
- flutter_local_notifications 5.0.0-nullsafety.1 [flutter flutter_local_notifications_platform_interface platform timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection meta path typed_data vector_math]
- font_awesome_flutter 9.0.0-nullsafety [flutter]
- formz 0.4.0-nullsafety.0
- google_maps_flutter 2.0.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
- image_picker 0.7.2 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- intl 0.17.0 [clock path]
- path_provider 2.0.1 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- simple_html_css 3.0.1 [flutter html_unescape xml]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.5.0 [collection]
- boolean_selector 2.1.0 [source_span string_scanner]
- camera_platform_interface 2.0.1 [flutter meta plugin_platform_interface cross_file stream_transform]
- characters 1.1.0
- charcode 1.2.0
- clock 1.1.0
- cloud_firestore_platform_interface 4.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 1.0.0 [cloud_firestore_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.15.0
- cross_file 0.3.1 [flutter meta]
- fake_async 1.2.0 [clock collection]
- ffi 1.0.0
- file 6.1.0 [meta path]
- firebase_auth_platform_interface 4.0.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 1.0.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.0.0 [flutter meta plugin_platform_interface]
- firebase_core_web 1.0.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 2.0.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 1.0.0 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 2.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 1.0.0 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- flutter_local_notifications_platform_interface 3.0.0-nullsafety.4 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.0 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- google_maps_flutter_platform_interface 2.0.1 [flutter meta plugin_platform_interface stream_transform collection]
- html_unescape 2.0.0-nullsafety.0
- http 0.13.0 [http_parser meta path pedantic]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image_picker_platform_interface 2.0.1 [flutter meta http plugin_platform_interface]
- js 0.6.3
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- nested 1.0.0 [flutter]
- path 1.8.0
- path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 2.0.0 [flutter]
- path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface]
- path_provider_windows 2.0.0 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.11.0
- petitparser 4.0.2 [meta]
- platform 3.0.0
- plugin_platform_interface 2.0.0 [meta]
- process 4.1.0 [file path platform]
- provider 5.0.0-nullsafety.5 [collection flutter nested]
- quiver 3.0.0 [matcher]
- sky_engine 0.0.99
- source_span 1.8.0 [charcode collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.7.0-nullsafety.0 [path]
- typed_data 1.3.0 [collection]
- vector_math 2.1.0
- win32 2.0.0 [ffi]
- xdg_directories 0.2.0 [meta path process]
- xml 5.0.2 [collection meta petitparser]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs AttentionThis issue needs maintainer attention.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions