Flutter app running on web failing with error:

Viewed 12808

**/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.**

5 Answers

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 :)

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

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.

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

Related