firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.97k forks source link

🐛 [firebase_messaging] FirebaseMessaging.onBackgroundMessage() makes main() method run twice #9947

Closed nivla360 closed 1 year ago

nivla360 commented 1 year ago

Bug report

Describe the bug When I include FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); in my code the main method gets called twice but when I remove it that's not the case.

Steps to reproduce

Steps to reproduce the behavior:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);
  FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
  print('App Running');
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    print('Inside build');
    return MaterialApp( home: Scaffold(body: Center(child: Text('Hello World')),));
  }
}

Then when I check the logs, you can see "App Running" is printed twice. This makes classes in my app initialize twice and causes problems in the app.

image

Expected behavior

main(); method should only be called once

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 3.3.8, on macOS 12.4 21F79 darwin-x64, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.73.0) [✓] Connected device (3 available) [✓] HTTP Host Availability • No issues found! ```

Flutter dependencies

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

Click To Expand ``` dependencies: - cloud_functions 4.0.4 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - cupertino_icons 1.0.5 - drift 2.2.0 [async convert collection js meta stream_channel sqlite3] - easy_debounce 2.0.2+1 - firebase_analytics 10.0.5 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.1.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.2.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_database 10.0.5 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter] - firebase_in_app_messaging 0.7.0+5 [firebase_core firebase_core_platform_interface firebase_in_app_messaging_platform_interface flutter meta] - firebase_messaging 14.1.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_storage 11.0.4 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_inappwebview 5.4.3+7 [flutter] - flutter_local_notifications 12.0.3 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_masked_text2 0.9.1 [flutter] - flutter_secure_storage 6.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - flutter_spinkit 5.1.0 [flutter] - flutter_styled_toast 2.1.3 [flutter flutter_localizations] - get 4.6.5 [flutter] - google_fonts 3.0.1 [flutter http path_provider crypto] - http 0.13.5 [async http_parser meta path] - intl 0.17.0 [clock path] - intl_phone_number_input 0.7.1 [flutter libphonenumber_plugin equatable collection] - ionicons 0.1.2 [flutter] - line_icons 2.0.1 [flutter] - lottie 2.0.0 [archive flutter path vector_math] - modal_bottom_sheet 2.1.2 [flutter] - open_file 3.2.1 [flutter ffi] - path 1.8.2 - path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - pdf 3.8.4 [archive barcode crypto image meta path_parsing vector_math xml] - permission_handler 10.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - pin_code_fields 7.4.0 [flutter] - share_plus 4.5.3 [cross_file meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web] - shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - sqlite3_flutter_libs 0.5.10 [flutter] dev dependencies: - build_runner 2.3.2 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - drift_dev 2.2.0+1 [charcode collection recase meta path json_annotation stream_transform args logging cli_util yaml io drift sqlite3 sqlparser analyzer analyzer_plugin source_span package_config pub_semver build build_resolvers build_config dart_style source_gen] - faker 2.0.0 [crypto] - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - line_awesome_flutter 2.0.0 [flutter] transitive dependencies: - _fe_analyzer_shared 49.0.0 [meta] - _flutterfire_internals 1.0.8 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 5.1.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - analyzer_plugin 0.11.2 [analyzer collection dart_style pub_semver yaml] - archive 3.3.2 [crypto path] - args 2.3.1 - async 2.9.0 [collection meta] - barcode 2.2.3 [meta qr] - boolean_selector 2.1.0 [source_span string_scanner] - build 2.3.1 [analyzer async convert crypto glob logging meta path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.10 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.6 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.4.1 [built_collection collection fixnum meta] - characters 1.2.1 - charcode 1.3.1 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cli_util 0.3.5 [meta path] - clock 1.1.1 - cloud_firestore_platform_interface 5.8.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.0.5 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.1.23 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.3.12 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - code_builder 4.3.0 [built_collection built_value collection matcher meta] - collection 1.16.0 - convert 3.1.1 [typed_data] - cross_file 0.3.3+2 [js meta] - crypto 3.0.2 [typed_data] - dart_style 2.2.4 [analyzer args path pub_semver source_span] - dbus 0.7.4 [args ffi meta xml] - equatable 2.0.5 [collection meta] - fake_async 1.3.1 [clock collection] - ffi 1.2.1 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.3.13 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+4 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.11.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.1.1 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.5.2 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.0.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_database_platform_interface 0.2.2+13 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_database_web 0.2.1+15 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins js] - firebase_in_app_messaging_platform_interface 0.2.1+25 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.2.6 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.6 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 4.1.22 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.3.14 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - fixnum 1.0.1 - flutter_local_notifications_linux 1.0.0 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math] - flutter_secure_storage_linux 1.1.1 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.1 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js] - flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 3.1.0 [async path] - glob 2.1.0 [async collection file path string_scanner] - graphs 2.1.0 [collection] - http_multi_server 3.2.1 [async] - http_parser 4.0.1 [collection source_span string_scanner typed_data] - image 3.2.2 [archive meta xml] - io 1.0.3 [meta path string_scanner] - js 0.6.4 - json_annotation 4.7.0 [meta] - libphonenumber 2.0.2 [flutter meta] - libphonenumber_platform_interface 0.3.1 [flutter plugin_platform_interface] - libphonenumber_plugin 0.2.3 [flutter flutter_web_plugins libphonenumber_platform_interface libphonenumber_web libphonenumber] - libphonenumber_web 0.2.0+1 [flutter flutter_web_plugins js libphonenumber_platform_interface] - lints 2.0.0 - logging 1.1.0 - matcher 0.12.12 [stack_trace] - material_color_utilities 0.1.5 - meta 1.8.0 - mime 1.0.2 - package_config 2.1.0 [path] - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.0.20 [flutter path_provider_platform_interface] - path_provider_ios 2.0.11 [flutter path_provider_platform_interface] - path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.6 [flutter path_provider_platform_interface] - path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface] - path_provider_windows 2.0.7 [ffi flutter path path_provider_platform_interface win32] - permission_handler_android 10.2.0 [flutter permission_handler_platform_interface] - permission_handler_apple 9.0.7 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.9.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.2 [flutter permission_handler_platform_interface] - petitparser 5.1.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.2 [collection meta] - pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml] - qr 3.0.1 [meta] - recase 4.1.0 - share_plus_linux 3.0.1 [cross_file share_plus_platform_interface file flutter meta url_launcher] - share_plus_macos 3.0.1 [share_plus_platform_interface flutter] - share_plus_platform_interface 3.1.2 [cross_file flutter meta mime plugin_platform_interface] - share_plus_web 3.1.0 [cross_file share_plus_platform_interface url_launcher flutter flutter_web_plugins meta mime] - share_plus_windows 3.0.1 [share_plus_platform_interface flutter meta url_launcher] - shared_preferences_android 2.0.14 [flutter shared_preferences_platform_interface] - shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.1.0 [flutter plugin_platform_interface] - shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.4.0 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.2 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.2.6 [analyzer async build dart_style glob meta path source_span yaml] - source_span 1.9.0 [collection path term_glyph] - sqlite3 1.9.1 [collection ffi js meta path] - sqlparser 0.23.3 [meta collection source_span charcode] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.1 - string_scanner 1.1.1 [source_span] - term_glyph 1.2.1 - test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.9.0 [path] - timing 1.0.0 [json_annotation] - typed_data 1.3.1 [collection] - url_launcher 6.1.6 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_launcher_android 6.0.19 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.1 [flutter plugin_platform_interface] - url_launcher_web 2.0.13 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface] - vector_math 2.1.2 - watcher 1.0.2 [async path] - web_socket_channel 2.2.0 [async crypto stream_channel] - win32 2.6.1 [ffi] - xdg_directories 0.2.0+2 [meta path process] - xml 6.1.0 [collection meta petitparser] - yaml 3.1.1 [collection source_span string_scanner] ```

Abhilashkv013 commented 1 year ago

https://github.com/firebase/flutterfire/issues/9932#issuecomment-1315047840

darshankawar commented 1 year ago

Closing this as duplicate of https://github.com/firebase/flutterfire/issues/9912