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.67k stars 3.97k forks source link

πŸ› [firebase_messaging] App crash when open a notification. #4927

Closed LutfiGarzon closed 3 years ago

LutfiGarzon commented 3 years ago

Bug report

While I have the app working both on android and iOS the notifications work fine, but if you kill the app (TERMINATED), if you receive a notification while the app is killed you'll open the app but will crash on start.

Steps to reproduce

  1. App state terminated.
  2. Incoming notification from FCM.
  3. touch the notification.
  4. On start the app crash no more activity.
  5. must restart the app kill and open again to enter without crash.

Expected behavior

When I open the app want to see my FirebaseMessaging.onMessageOpenedApp to behave as expected open my Local notification rendered, it works if the app was on Resume state but on Terminated state it just crash.

Additional context

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` flutter doctor -v [βœ“] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en-PA) β€’ Flutter version 1.22.5 at /flutter β€’ Framework revision 7891006299 (8 weeks ago), 2020-12-10 11:54:40 -0800 β€’ Engine revision ae90085a84 β€’ Dart version 2.10.4 [βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3) β€’ Android SDK at /android/sdk β€’ Platform android-29, build-tools 29.0.3 β€’ ANDROID_SDK_ROOT = /Android/sdk β€’ Java binary at: /Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 12.3) β€’ Xcode at /Developer β€’ Xcode 12.3, Build version 12C33 β€’ CocoaPods version 1.10.1 [βœ“] Android Studio (version 3.5) β€’ Android Studio at /Contents β€’ Flutter plugin version 44.0.1 β€’ Dart plugin version 191.8593 β€’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) [!] IntelliJ IDEA Ultimate Edition (version 2020.2.2) β€’ IntelliJ at /Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app βœ— Flutter plugin not installed; this adds Flutter specific functionality. <- ignore these they are fully working βœ— Dart plugin not installed; this adds Dart specific functionality. <- ignore these they are fully working β€’ For information about installing plugins, see https://flutter.dev/intellij-setup/#installing-the-plugins [βœ“] Connected device (1 available) β€’ Pixel 3a (mobile) β€’ 9C4AY1M4V8 β€’ android-arm64 β€’ Android 11 (API 30) ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.10.4 Flutter SDK 1.22.5 employee 1.0.0+1 dependencies: - audioplayers 0.17.0 [uuid path_provider flutter flutter_web_plugins] - auto_size_text 2.1.0 [flutter] - badges 1.1.6 [flutter] - beacon_broadcast 0.2.3 [flutter] - bot_toast 3.0.5 [flutter] - cached_network_image 2.5.0 [flutter flutter_cache_manager octo_image] - charts_flutter 0.8.1 [charts_common collection flutter intl logging meta] - collection 1.15.0-nullsafety.3 - community_material_icon 5.8.55 [flutter] - connectivity 2.0.2 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - cupertino_icons 1.0.0 - date_range_picker 1.0.6 [flutter] - decimal 0.3.5 [rational] - device_info 1.0.0 [flutter device_info_platform_interface] - firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_messaging 8.0.0-dev.14 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web] - flappy_search_bar 1.7.2 [flutter async flutter_staggered_grid_view] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_masked_text 0.8.0 [flutter] - flutter_native_timezone 1.0.4 [flutter] - flutter_screenutil 4.0.2+2 [flutter] - flutter_secure_storage 3.3.5 [meta flutter] - hive 1.4.4+1 [meta crypto] - hive_flutter 0.3.1 [flutter hive path_provider path] - http 0.12.2 [http_parser path pedantic] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image_cropper 1.3.1 [flutter] - image_picker 0.6.7+17 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - jiffy 3.0.1 [intl] - libphonenumber 1.0.2 [flutter meta] - path 1.8.0-nullsafety.1 - path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - rflutter_alert 1.1.0 [flutter] - shimmer 1.1.2 [flutter] - smooth_star_rating 1.1.1 [flutter] - uri 0.11.3+1 [matcher quiver utf] - webview_flutter 1.0.7 [flutter] dev dependencies: - build_runner 1.10.11 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_launcher_icons 0.7.5 [image args yaml] - 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] - hive_generator 0.8.2 [build source_gen hive analyzer dartx] transitive dependencies: - _fe_analyzer_shared 14.0.0 [meta] - analyzer 0.41.1 [_fe_analyzer_shared args cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 2.0.13 [crypto args path] - args 1.6.0 - async 2.5.0-nullsafety.1 [collection] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - build 1.6.0 [analyzer async convert crypto logging meta path glob] - build_config 0.4.5 [checked_yaml json_annotation meta path pubspec_parse yaml] - build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 1.5.1 [analyzer build crypto graphs logging meta path package_config pool pub_semver] - build_runner_core 6.1.5 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml] - built_collection 4.3.2 [collection quiver] - built_value 7.1.0 [built_collection collection fixnum quiver] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - charts_common 0.8.1 [collection intl logging meta vector_math] - checked_yaml 1.0.4 [json_annotation source_span yaml] - cli_util 0.2.0 [path] - clock 1.1.0-nullsafety.1 - code_builder 3.5.0 [built_collection built_value collection matcher meta] - connectivity_for_web 0.3.1+4 [connectivity_platform_interface flutter_web_plugins flutter] - connectivity_macos 0.1.0+7 [flutter] - connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface] - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - dart_style 1.3.10 [analyzer args path source_span] - dartx 0.5.0 [collection path crypto characters time meta] - device_info_platform_interface 1.0.1 [flutter meta plugin_platform_interface] - fake_async 1.2.0-nullsafety.1 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_messaging_platform_interface 1.0.0-dev.10 [flutter meta firebase_core plugin_platform_interface] - firebase_messaging_web 0.1.0-dev.5 [flutter flutter_web_plugins meta firebase_core firebase_core_web firebase_messaging_platform_interface js service_worker] - fixnum 0.10.11 - flutter_blurhash 0.5.0 [flutter meta] - flutter_cache_manager 2.1.0 [flutter path_provider uuid http path sqflite pedantic clock file rxdart image] - flutter_plugin_android_lifecycle 1.0.11 [flutter] - flutter_staggered_grid_view 0.3.3 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - glob 1.2.0 [async collection node_io path pedantic string_scanner] - graphs 0.2.0 - http_multi_server 2.2.0 [async] - image 2.1.19 [archive xml meta] - image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface] - intl 0.16.1 [path] - io 0.3.4 [charcode meta path string_scanner] - js 0.6.2 - json_annotation 3.1.1 - logging 0.11.4 - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.3 - mime 0.9.7 - node_interop 1.2.1 [js] - node_io 1.2.0 [file node_interop path] - octo_image 0.3.0 [flutter flutter_blurhash] - package_config 1.9.3 [path charcode] - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+6 [flutter] - path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface] - path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.9.2 [meta] - petitparser 3.1.0 [meta] - platform 2.2.1 - plugin_platform_interface 1.0.3 [meta] - pool 1.4.0 [async stack_trace] - process 3.0.13 [file intl meta path platform] - pub_semver 1.4.4 [collection] - pubspec_parse 0.1.7 [checked_yaml json_annotation pub_semver yaml] - quiver 2.1.5 [matcher meta] - rational 0.3.8 - rxdart 0.25.0 - service_worker 0.2.4 [js] - shelf 0.7.9 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel] - sky_engine 0.0.99 - source_gen 0.9.10+1 [analyzer async build dart_style glob meta path pedantic source_span] - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - sqflite 1.3.2+1 [flutter sqflite_common path] - sqflite_common 1.0.2+1 [synchronized path meta] - stack_trace 1.10.0-nullsafety.1 [path] - stream_channel 2.1.0-nullsafety.1 [async] - stream_transform 1.2.0 - string_scanner 1.1.0-nullsafety.1 [charcode source_span] - synchronized 2.2.0+2 - term_glyph 1.2.0-nullsafety.1 - test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - time 1.4.0 - timing 0.1.1+3 [json_annotation] - typed_data 1.3.0-nullsafety.3 [collection] - utf 0.9.0+5 - uuid 2.2.2 [crypto convert] - vector_math 2.1.0-nullsafety.3 - watcher 0.9.7+15 [async path pedantic] - web_socket_channel 1.1.0 [async crypto stream_channel] - win32 1.7.4 [ffi] - xdg_directories 0.1.2 [meta path process] - xml 4.5.1 [collection convert meta petitparser] - yaml 2.2.1 [charcode collection string_scanner source_span] ```

markusaksli-nc commented 3 years ago

Hi @LutfiGarzon There was a similar issue before https://github.com/FirebaseExtended/flutterfire/issues/4896 Could you provide your error logs and make sure you have followed all of the official Firebase documentation https://firebase.flutter.dev/docs/overview Thank you

LutfiGarzon commented 3 years ago

Hi, @markusaksli-nc So the problem wasn't direct connected to Firebase was something related to my routing inside the app. I'm using the installation process from FlutterFire for android and iOS.

fix the problem

  1. add this line of code.
  2. in my pubspec.yaml added firebase_analytics
    
    final message = await _fcm.getInitialMessage();

if (message != null) { // code goes here }

3. also add to my material app this line of code

MaterialApp( onUnknownRoute: (RouteSettings settings) { // open your app when is executed from outside when is terminated. } )