'Flutter app running on web failing with error:

**/C:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_web-2.2.8/lib/src/internals.dart:11:10: Error: Method not found: 'guardWebExceptions'. return internals.guardWebExceptions( ^^^^^^^^^^^^^^^^^^

/C:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:13:11:

Error: Method not found: 'Error.throwWithStackTrace'. Error.throwWithStackTrace(exception, stackTrace); ^^^^^^^^^^^^^^^^^^^

/C:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:16:9:

Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace( ^^^^^^^^^^^^^^^^^^^

/C:/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:11:7:

Error: A non-null value must be returned since the return type 'Never' doesn't allow null. Never convertPlatformException(Object exception, StackTrace stackTrace) { ^ Failed to compile application.**



Solution 1:[1]

I found a solution for this.

I added it to my pubspeck.yaml:

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6

Have a good day :)

Solution 2:[2]

There were changes made to the dependencies of the Flutter Firebase packages https://github.com/FirebaseExtended/flutterfire/pull/8156

You can either update to use 2.16.0 version of dart or newer. Or override the dependencies, you only need to add the ones that you are using

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6
  firebase_storage_platform_interface: 4.0.14
  cloud_functions_platform_interface: 5.0.21
  cloud_firestore_platform_interface: 5.4.13
  firebase_auth_platform_interface: 6.1.11
  firebase_database_platform_interface: 0.2.0+5

Solution 3:[3]

I have faced the same problem and got a workaround for this.

override firebase_messaging_platform_interface in pubspeck.yaml:

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6

check ref: https://github.com/FirebaseExtended/flutterfire/issues/8181

Solution 4:[4]

As pointed out earlier by GarrettBarlocker, dependency overrides of all the firebase dependencies used in my project did the trick for me and it solved the problem.

Don't try flutter upgrade as it upgrades your project to the latest version of the flutter release. And it will force you to migrate your project to android v2 embedding as v1 embedding is deprecated in flutter 2.10.2 thereby failing to compile and build the application. Also, you may face compatibility issues with other dependencies.

Solution 5:[5]

remove the firebase ^9.0.2 from the pubspec.yaml file because this partucular one is for Web apps and you're trying to build an android app

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sonu Saini
Solution 2 Garrett Barlocker
Solution 3 Sultan Mahmud
Solution 4
Solution 5 Ghaith Mefteh