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

🐛 [firebase-messaging ] [web] Uncaught MissingPluginException(No implementation found for method Messaging#requestPermission on channel plugins.flutter.io/firebase_messaging) #11994

Closed CobeyH closed 8 months ago

CobeyH commented 9 months ago

Bug report

Describe the bug My Dart code throws an error when I try to request permissions for Firebase Messaging on Flutter Web. The permissions request was originally contained within a Riverpod provider, but I also tried within the main function and also within the initState of a stateful widget that is displayed upon login.

The notifications work flawlessly on Android and also when running my web app locally (from terminal and from debugger). However, when I deploy the application to the staging environment, the error is shown in the console.

Steps to reproduce

Steps to reproduce the behavior:

  1. Setup Firebase as per the instructions here: https://firebase.google.com/docs/cloud-messaging/flutter/client#android

  2. Add the code below into the main function of the dart application:

    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
    );
    final firebaseMessaging = FirebaseMessaging.instance;
    final permissions =
      await firebaseMessaging.requestPermission(provisional: true);
    print(permissions);
    runApp(const ProviderScope(child: MyApp()));
    }
  3. See see the error below: Uncaught MissingPluginException(No implementation found for method Messaging#requestPermission on channel [plugins.flutter.io/firebase_messaging](http://plugins.flutter.io/firebase_messaging))

  4. The print statement is never called with the received permissions.

Expected behavior

A notification should appear that asks the user to grant permission to show notifications.

Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 3.13.9, on Ubuntu 22.04.3 LTS 6.2.0-37-generic, locale en_CA.UTF-8) • Flutter version 3.13.9 on channel stable at /home/cobey/flutter • Upstream repository git@github.com:flutter/flutter.git • Framework revision d211f42860 (6 weeks ago), 2023-10-25 13:42:25 -0700 • Engine revision 0545f8705d • Dart version 3.1.5 • DevTools version 2.25.0 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /home/cobey/Android/Sdk • Platform android-33, build-tools 33.0.0 • ANDROID_SDK_ROOT = /home/cobey/Android/Sdk • Java binary at: /home/cobey/Downloads/android-studio/android-studio/jbr/bin/java • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) • All Android licenses accepted. [✓] Chrome - develop for the web • Chrome at google-chrome [✓] Linux toolchain - develop for Linux desktop • Ubuntu clang version 14.0.0-1ubuntu1.1 • cmake version 3.22.1 • ninja version 1.10.1 • pkg-config version 0.29.2 [✓] Android Studio (version 2021.2) • Android Studio at /usr/local/android-studio • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] Android Studio (version 2022.1) • Android Studio at /home/cobey/Downloads/android-studio/android-studio • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) [✓] VS Code (version 1.84.2) • VS Code at /usr/share/code • Flutter extension version 3.78.0 [✓] Connected device (2 available) • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.3 LTS 6.2.0-37-generic • Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.159 [✓] Network resources • All expected network resources are available. • No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 3.1.5 Flutter SDK 3.13.9 stocadro 2.9.0 dependencies: - auto_size_text 3.0.0 [flutter] - collection 1.17.2 - commons 1.3.1 [flutter http flutter_secure_storage collection intl flutter_spinkit searchfield flutter_riverpod riverpod_annotation package_info_plus firebase_analytics firebase_core flutter_localizations page_transition] - csv 5.1.1 - cupertino_icons 1.0.6 - dio 5.4.0 [async http_parser meta path] - excel 2.1.0 [archive xml collection equatable] - file_picker 5.5.0 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32] - firebase_analytics 10.7.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 2.24.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.7.7 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_riverpod 2.4.9 [collection flutter meta riverpod state_notifier] - flutter_secure_storage 7.0.1 [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.2.0 [flutter] - google_fonts 6.1.0 [flutter http path_provider crypto] - http 1.1.0 [async http_parser meta] - image_cropper 5.0.1 [flutter image_cropper_platform_interface image_cropper_for_web] - image_picker 1.0.4 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows] - image_picker_for_web 3.0.1 [flutter flutter_web_plugins image_picker_platform_interface mime] - intl 0.18.1 [clock meta path] - logger 2.0.2+1 - multi_select_flutter 4.1.3 [flutter collection] - searchfield 0.8.9 [flutter] - sizer 2.0.15 [universal_io flutter] - web_socket_channel 2.4.0 [async crypto stream_channel] dev dependencies: - custom_lint 0.5.7 [analyzer analyzer_plugin args async ci cli_util collection freezed_annotation json_annotation meta package_config path pub_semver pubspec_parse rxdart uuid yaml] - flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_lints 2.0.3 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] - riverpod_lint 2.3.7 [analyzer analyzer_plugin collection custom_lint_builder meta path riverpod riverpod_analyzer_utils source_span yaml] transitive dependencies: - _fe_analyzer_shared 64.0.0 [meta] - _flutterfire_internals 1.3.15 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 6.2.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - analyzer_plugin 0.11.3 [analyzer collection dart_style pub_semver yaml] - archive 3.4.9 [crypto path pointycastle] - args 2.4.2 - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - checked_yaml 2.0.3 [json_annotation source_span yaml] - ci 0.1.0 - cli_util 0.4.0 [meta path] - clock 1.1.1 - convert 3.1.1 [typed_data] - cross_file 0.3.3+7 [js meta] - crypto 3.0.3 [typed_data] - custom_lint_builder 0.5.7 [analyzer analyzer_plugin collection custom_lint custom_lint_core glob hotreloader meta path pubspec_parse rxdart] - custom_lint_core 0.5.7 [analyzer analyzer_plugin collection custom_lint matcher meta path pubspec_parse source_span yaml] - dart_style 2.3.4 [analyzer args collection path pub_semver source_span] - equatable 2.0.5 [collection meta] - fake_async 1.3.1 [clock collection] - ffi 2.1.0 - file 7.0.0 [meta path] - file_selector_linux 0.9.2+1 [cross_file file_selector_platform_interface flutter] - file_selector_macos 0.9.3+3 [cross_file file_selector_platform_interface flutter] - file_selector_platform_interface 2.6.1 [cross_file flutter http plugin_platform_interface] - file_selector_windows 0.9.3+1 [cross_file file_selector_platform_interface flutter] - firebase_analytics_platform_interface 3.8.3 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.5+10 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.10.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.5.16 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.16 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math web] - flutter_plugin_android_lifecycle 2.0.17 [flutter] - flutter_secure_storage_linux 1.2.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 2.0.1 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.2 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.2 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 1.1.3 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - freezed_annotation 2.4.1 [collection json_annotation meta] - glob 2.1.2 [async collection file path string_scanner] - hotreloader 4.1.0 [collection logging path stream_transform vm_service watcher] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.1.3 [archive meta xml] - image_cropper_for_web 3.0.0 [flutter flutter_web_plugins image_cropper_platform_interface js] - image_cropper_platform_interface 5.0.0 [flutter plugin_platform_interface http] - image_picker_android 0.8.8+2 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_ios 0.8.8+4 [flutter image_picker_platform_interface] - image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_macos 0.2.1+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_platform_interface 2.9.1 [cross_file flutter http plugin_platform_interface] - image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - lints 2.1.1 - logging 1.2.0 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.9.1 - mime 1.0.4 - package_config 2.1.0 [path] - package_info_plus 4.2.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - page_transition 2.1.0 [flutter] - path 1.8.3 - path_provider 2.1.1 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.2.1 [flutter path_provider_platform_interface] - path_provider_foundation 2.3.1 [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.1 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32] - petitparser 5.4.0 [meta] - platform 3.1.3 - plugin_platform_interface 2.1.7 [meta] - pointycastle 3.7.3 [collection convert js] - pub_semver 2.1.4 [collection meta] - pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml] - riverpod 2.4.9 [meta stack_trace state_notifier] - riverpod_analyzer_utils 0.5.0 [analyzer collection crypto custom_lint_core freezed_annotation meta path source_span] - riverpod_annotation 2.3.3 [meta riverpod] - rxdart 0.27.7 - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sprintf 7.0.0 - stack_trace 1.11.0 [path] - state_notifier 1.0.0 [meta] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - typed_data 1.3.2 [collection] - universal_io 2.2.2 [collection meta typed_data] - uuid 4.2.1 [crypto sprintf meta] - vector_math 2.1.4 - vm_service 13.0.0 - watcher 1.1.0 [async path] - web 0.1.4-beta - win32 5.1.1 [ffi] - xdg_directories 1.0.3 [meta path] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

darshankawar commented 9 months ago

Thanks for the report @CobeyH In the code sample you shared, I see that you are using ProviderScope presumably coming from provider package ? I actually tried using the plugin example with which I didn't get the mentioned error, so can you check the same and compare with your implementation to see if using it, do you still see the error ?

CobeyH commented 9 months ago

Thank you @darshankawar, I deployed the example application to the staging environment and it works as expected. I will try to determine how my application is different from the example app and post an update for others if I fix it. The ProviderScope is there for the Riverpod 2.0 package.

google-oss-bot commented 9 months ago

Hey @CobeyH. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 8 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@CobeyH if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.