Closed ChurikiTenna closed 1 month ago
Hi @ChurikiTenna , This issue appears to be coming from the flutter_local_notifications
package and not FirebaseMessaging.onBackgroundMessage
. What you can do is isolate the callback function you pass to the onDidReceiveBackgroundNotificationResponse
of your localNotifications.initialize
. Make it a top level function and annotate it with @pragma('vm:entry-point')
. Like so...
// This should be a top level function
@pragma('vm:entry-point')
onDidReceiveBackgroundNotificationResponse(NotificationResponse notificationResponse){
// some code
}
localNotifications.initialize(
...,
onDidReceiveBackgroundNotificationResponse: onDidReceiveBackgroundNotificationResponse,
);
Please try this out and give me feedback.
@SelaseKay Oh shoot. how did I missed this. It is solved. Thank you!!
Is there an existing issue for this?
Which plugins are affected?
Messaging
Which platforms are affected?
iOS
Description
I am using
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
for receiving push notification, but it saysThe backgroundHandler needs to be either a static function or a top
even though it's on the top level. I have also tried putting firebaseMessagingBackgroundHandler in to a class as a static function, but it also failed with the same error.Reproducing the issue
call this:
Firebase Core version
15.0.3
Flutter Version
3.22.2
Relevant Log Output
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter_local_notifications/src/platform_flutter_local_notifications.dart': Failed assertion: line 1030 pos 12: 'callback != null': The backgroundHandler needs to be either a static function or a top level function to be accessible as a Flutter entry point.
0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
2 _evaluateBackgroundNotificationCallback (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:1030:12)
3 IOSFlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:642:5)
4 FlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:157:13)
5 main (package:pln_getx/main.dart:68:24)
Expand
Flutter dependencies
snippet```yaml % flutter pub deps -- --style=compact Dart SDK 3.4.3 Flutter SDK 3.22.2 pln_getx 3.0.2+300033 dependencies: - advertising_id 2.6.0 [flutter] - app_tracking_transparency 2.0.5 [flutter] - barcode_widget 2.0.4 [barcode flutter] - connectivity_plus 6.0.3 [flutter flutter_web_plugins connectivity_plus_platform_interface web meta nm collection] - cupertino_icons 1.0.8 - dio 5.5.0+1 [async http_parser meta path dio_web_adapter] - encrypt 5.0.3 [args asn1lib clock collection crypto pointycastle] - firebase_core 3.2.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 15.0.3 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_remote_config 5.0.3 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_inappwebview 6.0.0 [flutter flutter_inappwebview_platform_interface flutter_inappwebview_android flutter_inappwebview_ios flutter_inappwebview_macos flutter_inappwebview_web] - flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_local_notifications 17.2.1+1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_native_splash 2.4.1 [args flutter flutter_web_plugins html image meta path universal_io xml yaml ansicolor] - flutter_svg 2.0.10+1 [flutter http vector_graphics vector_graphics_codec vector_graphics_compiler] - font_awesome_flutter 10.7.0 [flutter] - get 4.6.6 [flutter] - get_storage 2.1.1 [flutter get path_provider] - http 1.2.1 [async http_parser meta web] - package_info_plus 8.0.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock] - path_provider 2.1.3 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - permission_handler 11.3.1 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface] - push 2.3.0 [flutter push_platform_interface push_android push_ios push_macos] - shared_preferences 2.2.3 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - url_launcher 6.3.0 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - uuid 4.4.2 [crypto sprintf meta fixnum] - vector_graphics 1.1.11+1 [flutter http vector_graphics_codec] - webview_flutter 4.8.0 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] dev dependencies: - flutter_lints 4.0.0 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service] dependency overrides: - webview_flutter_android 3.16.1 [flutter webview_flutter_platform_interface] transitive dependencies: - _flutterfire_internals 1.3.39 [collection firebase_core firebase_core_platform_interface flutter meta] - ansicolor 2.0.2 - archive 3.6.1 [crypto path] - args 2.5.0 - asn1lib 1.5.3 - async 2.11.0 [collection meta] - barcode 2.2.8 [meta qr] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - checked_yaml 2.0.3 [json_annotation source_span yaml] - cli_util 0.4.1 [meta path] - clock 1.1.1 - collection 1.18.0 - connectivity_plus_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - convert 3.1.1 [typed_data] - crypto 3.0.3 [typed_data] - csslib 1.0.0 [source_span] - dbus 0.7.10 [args ffi meta xml] - dio_web_adapter 1.0.1 [dio http_parser meta] - fake_async 1.3.1 [clock collection] - ffi 2.1.2 - file 7.0.0 [meta path] - firebase_core_platform_interface 5.1.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.17.3 [firebase_core_platform_interface flutter flutter_web_plugins meta web] - firebase_messaging_platform_interface 4.5.41 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.8.11 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web] - firebase_remote_config_platform_interface 1.4.39 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.6.11 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins] - fixnum 1.1.0 - flutter_inappwebview_android 1.0.13 [flutter flutter_inappwebview_platform_interface] - flutter_inappwebview_internal_annotations 1.1.1 - flutter_inappwebview_ios 1.0.13 [flutter flutter_inappwebview_platform_interface] - flutter_inappwebview_macos 1.0.11 [flutter flutter_inappwebview_platform_interface] - flutter_inappwebview_platform_interface 1.0.10 [flutter flutter_inappwebview_internal_annotations plugin_platform_interface] - flutter_inappwebview_web 1.0.8 [flutter flutter_web_plugins js flutter_inappwebview_platform_interface] - flutter_local_notifications_linux 4.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 7.2.0 [flutter plugin_platform_interface] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math] - html 0.15.4 [csslib source_span] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.2.0 [archive meta xml] - js 0.6.7 [meta] - json_annotation 4.9.0 [meta] - leak_tracker 10.0.4 [clock collection meta path vm_service] - leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta] - leak_tracker_testing 3.0.1 [leak_tracker matcher meta] - lints 4.0.0 - matcher 0.12.16+1 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.8.0 [collection] - meta 1.12.0 - nm 0.5.0 [dbus] - package_info_plus_platform_interface 3.0.0 [flutter meta plugin_platform_interface] - path 1.9.0 - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.2.7 [flutter path_provider_platform_interface] - path_provider_foundation 2.4.0 [flutter path_provider_platform_interface] - path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface] - path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface] - permission_handler_android 12.0.7 [flutter permission_handler_platform_interface] - permission_handler_apple 9.4.5 [flutter permission_handler_platform_interface] - permission_handler_html 0.1.1 [flutter flutter_web_plugins permission_handler_platform_interface] - permission_handler_platform_interface 4.2.1 [flutter meta plugin_platform_interface] - permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface] - petitparser 6.0.2 [meta] - platform 3.1.5 - plugin_platform_interface 2.1.8 [meta] - pointycastle 3.9.1 [collection convert js] - push_android 0.6.0 [flutter push_platform_interface] - push_ios 0.5.1 [flutter push_platform_interface] - push_macos 0.0.1 [flutter cupertino_icons] - push_platform_interface 0.6.0 [flutter plugin_platform_interface] - qr 3.0.1 [meta] - shared_preferences_android 2.2.3 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.4.0 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.3.2 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.3.2 [flutter plugin_platform_interface] - shared_preferences_web 2.3.0 [flutter flutter_web_plugins shared_preferences_platform_interface web] - shared_preferences_windows 2.3.2 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sprintf 7.0.0 - stack_trace 1.11.1 [path] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - timezone 0.9.4 [path] - typed_data 1.3.2 [collection] - universal_io 2.2.2 [collection meta typed_data] - url_launcher_android 6.3.3 [flutter url_launcher_platform_interface] - url_launcher_ios 6.3.1 [flutter url_launcher_platform_interface] - url_launcher_linux 3.1.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.2.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface] - url_launcher_web 2.3.1 [flutter flutter_web_plugins url_launcher_platform_interface web] - url_launcher_windows 3.1.1 [flutter url_launcher_platform_interface] - vector_graphics_codec 1.1.11+1 - vector_graphics_compiler 1.1.11+1 [args meta path_parsing xml vector_graphics_codec path] - vector_math 2.1.4 - vm_service 14.2.1 - web 0.5.1 - webview_flutter_platform_interface 2.10.0 [flutter meta plugin_platform_interface] - webview_flutter_wkwebview 3.14.0 [flutter path webview_flutter_platform_interface] - win32 5.5.1 [ffi] - xdg_directories 1.0.4 [meta path] - xml 6.5.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```