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.61k stars 3.95k forks source link

firebase_messaging - onTokenRefresh not firing #5543

Closed vytautas-pranskunas- closed 3 years ago

vytautas-pranskunas- commented 3 years ago

I am using firebase_messaging: ^8.0.0-dev.14

Before migration to this version this was working fien. After migration I noticed that it is not firing any more.

await await Firebase.initializeApp();
FirebaseMessaging.instance.onTokenRefresh.takeUntil(_unsubscriber).listen((newToken) {
      _securityService.saveToken(token: newToken);

      print(newToken);
    });

I cannot migrate to latests version with null safety to check because i have other dependencies which are not migrated yet.

I have tried:

nothing helps

Any advice?

markusaksli-nc commented 3 years ago

Hi @vytautas-pranskunas- Could you please provide your flutter doctor -v and flutter pub deps -- --style=compact? When are you expecting this stream to fire? Thank you

vytautas-pranskunas- commented 3 years ago

Hi, I do expect it to fire upon app start (fresh) or when token is refreshed.

Fresh meaning:

[√] Flutter (Channel unknown, 1.22.6, on Microsoft Windows [Version 10.0.19041.867], locale en-US)
    • Flutter version 1.22.6 at D:\flutter
    • Framework revision 9b2d32b605 (10 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at C:\Users\Vytautas\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.54.3)
    • VS Code at C:\Users\Vytautas\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.20.0

[√] Connected device (2 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
    • sdk gphone x86 (mobile) • emulator-5556 • android-x86 • Android 11 (API 30) (emulator)
Dart SDK 2.10.5
Flutter SDK 1.22.6

dependencies:
- apple_sign_in 0.1.0 [flutter]
- cached_network_image 2.5.1 [flutter flutter_cache_manager octo_image]
- country_code_picker 1.7.0 [flutter modal_bottom_sheet]
- cupertino_icons 1.0.0
- custom_pop_up_menu 1.1.2 [flutter]
- darq 0.4.0+1
- date_time_picker 1.1.1 [flutter intl]
- dio 3.0.10 [http_parser path]
- email_validator 1.0.6
- enum_to_string 1.0.14
- fancy_on_boarding 1.7.0 [flutter flutter_svg]
- firebase_auth 0.20.1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]        
- firebase_messaging 8.0.0-dev.15 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_facebook_login 3.0.0 [flutter collection]
- flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math]
- flutter_mobx 1.1.0+2 [mobx flutter]
- flutter_rating_bar 3.2.0+1 [flutter]
- flutter_signin_button 1.1.0 [flutter font_awesome_flutter]
- flutter_slidable 0.5.7 [flutter]
- flutter_spinkit 4.1.2+1 [flutter]
- fresh_dio 0.2.0 [dio meta fresh]
- fresh_graphql 0.4.0 [fresh graphql http meta pedantic]
- gender_selection 1.0.0 [flutter]
- geocoder 0.2.1 [meta flutter]
- geolocator 6.2.1 [flutter geolocator_platform_interface geolocator_web]
- get_it 5.0.6 [async meta]
- google_sign_in 4.5.9 [google_sign_in_platform_interface flutter meta google_sign_in_web]
- graphql_flutter 4.0.1 [graphql gql_exec flutter meta path_provider path connectivity hive]
- highlighter_coachmark 0.0.3 [flutter]
- hive 1.4.4+1 [meta crypto]
- hive_flutter 0.3.1 [flutter hive path_provider path]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- image_cropper 1.3.1 [flutter]
- image_picker 0.6.7+22 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- intl 0.16.1 [path]
- libphonenumber 1.0.2 [flutter meta]
- load 0.1.6 [flutter]
- location 3.2.4 [flutter location_platform_interface location_web meta]
- mobx 1.2.1+4 [meta]
- multi_image_picker 4.7.15 [flutter meta]
- objectdb 1.0.10+1 [execution_queue deeply]
- oktoast 2.3.2 [flutter]
- package_info 0.4.3+4 [flutter]
- passbase_flutter 2.1.7 [flutter]
- rxdart 0.24.1
- sentry 4.0.6 [http meta stack_trace uuid]
- table_calendar 2.3.3 [flutter intl simple_gesture_detector]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]    
- uuid 2.2.2 [crypto convert]

dev dependencies:
- build_runner 1.11.1 [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.8.1 [image args yaml path]
- 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]
- lefthook 0.6.5 [system_info archive cli_util]
- mobx_codegen 1.1.2 [analyzer build build_resolvers meta mobx path source_gen]

transitive dependencies:
- _fe_analyzer_shared 14.0.0 [meta]
- analyzer 0.41.2 [_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.2 [analyzer async convert crypto glob logging meta path]
- build_config 0.4.5 [checked_yaml json_annotation meta path pubspec_parse yaml]
- build_daemon 2.1.7 [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.3 [analyzer build crypto graphs logging meta path package_config pool pub_semver]
- build_runner_core 6.1.7 [async build build_config build_resolvers collection convert crypto glob graphs 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
- checked_yaml 1.0.4 [json_annotation source_span yaml]
- cli_util 0.1.4 [path]
- clock 1.1.0-nullsafety.1
- code_builder 3.7.0 [built_collection built_value collection matcher meta]
- collection 1.15.0-nullsafety.3
- connectivity 2.0.2 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- 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.12 [analyzer args path pub_semver source_span]
- deeply 1.1.0+1
- execution_queue 1.1.0+1
- fake_async 1.2.0-nullsafety.1 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- file_utils 0.1.4 [globbing path]
- firebase_auth_platform_interface 3.1.0 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.3 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js]
- firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- 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.6 [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.2 [flutter path_provider uuid http path sqflite pedantic clock file rxdart image]
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_svg 0.19.1 [flutter meta path_drawing vector_math xml]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- font_awesome_flutter 8.12.0 [flutter]
- fresh 0.3.0 [meta]
- geolocator_platform_interface 1.0.9 [flutter meta plugin_platform_interface vector_math]
- geolocator_web 1.0.1 [flutter flutter_web_plugins geolocator_platform_interface]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- globbing 0.3.1 [path]
- google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
- google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- gql 0.12.4 [source_span meta collection]
- gql_dedupe_link 1.0.10 [meta gql_exec gql_link async]
- gql_error_link 0.1.1-alpha+1601131172858 [async gql_exec gql_link meta]
- gql_exec 0.2.5 [gql meta collection]
- gql_http_link 0.3.2 [meta gql gql_exec gql_link http http_parser]
- gql_link 0.3.1 [meta gql gql_exec]
- gql_transform_link 0.1.5 [gql_exec gql_link]
- graphql 4.0.1 [meta path gql gql_exec gql_link gql_http_link gql_transform_link gql_error_link gql_dedupe_link hive normalize http collection websocket rxdart uuid_enhanced]
- graphs 0.2.0
- http 0.12.2 [http_parser path pedantic]
- http_multi_server 2.2.0 [async]
- image 2.1.19 [archive xml meta]
- image_picker_platform_interface 1.1.6 [flutter meta http plugin_platform_interface]
- io 0.3.5 [meta path string_scanner]
- js 0.6.2
- json_annotation 3.1.1
- location_platform_interface 1.1.0 [flutter meta plugin_platform_interface]
- location_web 1.0.1 [flutter flutter_web_plugins http_parser js location_platform_interface meta]
- logging 0.11.4
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- mime 0.9.7
- modal_bottom_sheet 1.0.0+1 [flutter]
- node_interop 1.2.1 [js]
- node_io 1.2.0 [file node_interop path]
- normalize 0.4.7 [gql meta]
- octo_image 0.3.0 [flutter flutter_blurhash]
- package_config 1.9.3 [path charcode]
- path 1.8.0-nullsafety.1
- path_drawing 0.4.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- path_provider 1.6.27 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+8 [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.8 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.5 [matcher meta]
- service_worker 0.2.4 [js]
- shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 0.2.4+1 [shelf stream_channel web_socket_channel]
- simple_gesture_detector 0.1.6 [flutter]
- sky_engine 0.0.99
- source_gen 0.9.10+3 [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+4 [flutter sqflite_common path]
- sqflite_common 1.0.3+3 [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
- system_info 0.1.3 [file_utils path]
- 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]
- timing 0.1.1+3 [json_annotation]
- typed_data 1.3.0-nullsafety.3 [collection]
- url_launcher_linux 0.0.1+4 [flutter]
- url_launcher_macos 0.0.1+9 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5+3 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+3 [flutter]
- uuid_enhanced 3.0.2 [crypto convert collection]
- vector_math 2.1.0-nullsafety.3
- watcher 0.9.7+15 [async path pedantic]
- web_socket_channel 1.2.0 [async crypto stream_channel]
- websocket 0.0.5
- win32 1.7.4+1 [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

Does the official example code not work for you?

Also, you can just upgrade to the latest versions of the packages since you don't need to migrate everything to null-safety at once. You can still use null-safe packages with mixed or no sound null safety.

vytautas-pranskunas- commented 3 years ago

@mark-veenstra I am not sure how can i use mixed nullsafety with non-nullsafety because null safety requires SDK min version upgrade. SDK min version forces to use other packages which, if not migrated to null safety, does not support it.

The officail docs before - worked as i said on my current version it is not.

markusaksli-nc commented 3 years ago

Well, the official example works on the latest version (it worked on the version you are using as well), and the stream fires as expected. Unless you provide a minimal complete reproducible code sample or some error logs I'm not sure there is anything to fix here.

You don't have to upgrade the min sdk constraint if you use the new versions. You can just run with flutter run --no-sound-null-safety or add

// @dart=2.9

to main.dart if you do upgrade the min constraint.

vytautas-pranskunas- commented 3 years ago

It worked on earlier version not current one. As I understand you do not run official example on version that I am using :)

I will try to use latest one as you said but this smels like hacky / silent bugs solution...

markusaksli-nc commented 3 years ago

Let's say that it is a genuine issue with the version you are using (which I'm only doubting because I triaged issues with that version all the way until 9.0 dev and never saw this issue come up for me or any reporter). Even if that is the case the only way you will get a fix for it is by just using the latest version so you will need to upgrade either way here.

Adding back the wait label for your testing.

vytautas-pranskunas- commented 3 years ago

I do not think that I understand correctly how to update but not update packages :)) if i run flutte rupgrade it upgrades all flutter SDK and dart SDK then i cannot compile project because many packages still not moved to null safety.

If i will upgrade only your package and add flutter run --no-sound-null-safety then it should fail because it will use null safety dart language versions.

So i do not really understand how can i have your package upgraded to latet version but use lower version of dart...Maybe you can be more clear?

vytautas-pranskunas- commented 3 years ago

for example if i try to add your package i get an error that your required min SDK version is higher and packages even not getting resolved....

markusaksli-nc commented 3 years ago

As I said you can opt out of nullsafety on the latest version of flutter with the run flag or adding

// @dart=2.9

to main.dart. The official example code already contains this so it is opted out of nullsafety by default.

All you should have to do is just flutter upgrade and upgrade the packages to the latest versions. After that, you can add the dart version comment to main.dart.

vytautas-pranskunas- commented 3 years ago

I do not think you are right... After i do flutter upgrade packages, that are not on null safety, stops resolving and pubspec.yaml starts complaining about minSdk version. So even if adding those // @dart=2.9 i would not be able to add any other package anymore because minSdk version will be changed.

markusaksli-nc commented 3 years ago

What error message or issue are you getting specifically here?

vytautas-pranskunas- commented 3 years ago

Thats a thing - I am not getting any error or any message. onTokenRefresh just is not called like it used to be with earlier version i used (it was 7+)

markusaksli-nc commented 3 years ago

No I mean when trying to upgrade the packages.

vytautas-pranskunas- commented 3 years ago

ah, so i get multiple errors in console saying that that and that package min sdk version is for example 2.7.0 and my project is 2.12.0

markusaksli-nc commented 3 years ago

I meant could you paste one of these errors in here

vytautas-pranskunas- commented 3 years ago

sure

Because my_project depends on fresh_graphql >=0.5.0 which requires SDK version >=2.12.0 <3.0.0, version solving failed.
pub get failed (1; Because senio_assist depends on fresh_graphql >=0.5.0 which requires SDK version >=2.12.0 <3.0.0, version solving failed.)
exit code 1
markusaksli-nc commented 3 years ago

What is the environment sdk constraint in your pubspec.yaml?

vytautas-pranskunas- commented 3 years ago

I pasted you wrong error - it is vice versa error I mean now my environment sdk is

environment:
  sdk: ">=2.7.0 <3.0.0"

but if i upgrade it to 2.12.0 then vice versa error start to show. that package requires SDK to be lower. I cannot give you now that error because i am working on project .. I had few attempts to upgrade it to 2.12.0 but always bump to the fact that some packages are not migrated yet and i cannot continue.

Maybe with your suggestions it might work but what from what i read on internet many people are facing many different problems trying to compile packages with no sound.

markusaksli-nc commented 3 years ago

Well given that we can't reproduce this issue on either version of messaging using the official example and you can't currently confirm whether it persists on the latest version there really isn't anything for us to do there.

Let me know if you can provide a minimal complete reproducible code sample that demonstrates the issue with just firebase_messaging on the latest version or if your whole project faces the issue on the latest version after you are able to upgrade.

Closing this for now.

vytautas-pranskunas- commented 3 years ago

Only 1 question - gave you even tried to checkout version that I use to try or just gentle refuse to support users that are not on latest version? 😊

markusaksli-nc commented 3 years ago

Yes I tried it with the version you are using.

vytautas-pranskunas- commented 3 years ago

And it works for you?

On Wed, Apr 14, 2021, 11:41 AM Markus Aksli @.***> wrote:

Yes I tried it with the version you are using.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/FirebaseExtended/flutterfire/issues/5543#issuecomment-819384529, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA54ZF6Z56EN6UV77MM5NUDTIVPNPANCNFSM42G3TIYQ .

markusaksli-nc commented 3 years ago

Yes, the token seems to be updated appropriately with

  firebase_messaging: ^8.0.0-dev.14
  flutter_local_notifications: ^4.0.1+2
  http: ^0.13.1

It could be that the call to getToken is this refreshing when the app is opened since they are both in initState in the official example. However there is already an open issue for the stream on its own not firing.

vytautas-pranskunas- commented 3 years ago

hi, thanks for trying. Did not get your last sentence.

What do you mean on its own?

vytautas-pranskunas- commented 3 years ago

Hi, so i have migrated to null safety whole project. FirebaseMessaging.instance.onTokenRefresh - not firing! I have uninstalled app, run flutter - did not receive new token. My code:

FirebaseMessaging.instance.onTokenRefresh.takeUntil(_unsubscriber!).listen((newToken) {
      print(newToken);
    });