'Method not found: 'guard'. return internals.guard(

i am new to flutter.when i run this code on flutter web this error occurs. .pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-1.0.7/lib/src/internals.dart:10:20:

some one help to get rid of the problem



Solution 1:[1]

If you updated your flutter sdk to Beta channel, Downgrade your flutter sdk to Stable Channel. Current stable version is 2.10.3

Flutter downgrade command

flutter downgrade v2.10.3

and than

Downgrade flutter to version 2.10.3
? [y|n]:
Type y for Yes to confirm changes

If the above method does'nt work try this

cloud_firestore: ^3.1.13 
cloud_firestore_web: ^2.6.13 

add the above the packages to your pubspec.yaml file with updated version

Solution 2:[2]

cloud_firestore: ^3.1.13 
cloud_firestore_web: ^2.6.13

add the above the packages to your pubspec.yaml file

Solution 3:[3]

Either you can upgrade your all firebase packages to the available latest version (Mainly firebase_core to the latest version) or else you can modify the error which we get for internals like below:

Step-1: Open the internals.dart file of the firebase package which you face the error.

Step-2: Change function use from internals.guard() to internals.guardWebExceptions() like below:

From:

return internals.guard(
    cb,
    plugin: 'app-check',
    codeParser: (code) => code.replaceFirst('appCheck/', ''),
  );

To:

return internals.guardWebExceptions(
    cb,
    plugin: 'app-check',
    codeParser: (code) => code.replaceFirst('appCheck/', ''),
  );

Notes:

  • This modification will remain locally so remember to change every time if you do flutter clean or run the app in a different system.
  • Above example is for Firebase AppCheck. You can get the same error for another firebase service. So, modify only that internals from the specific firebase service error that you have faced.

Solution 4:[4]

Below thing worked for me :

I upgraded :

firebase_core: ^1.0.4 to firebase_core: ^1.13.1

cloud_firestore: ^1.0.6 to cloud_firestore: ^3.1.10

firebase_analytics: ^9.1.0 -> firebase_analytics: ^9.1.2

Then do:

flutter clean

flutter run

Refer : https://github.com/firebase/flutterfire/issues/8194 For more info

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
Solution 2 Anandh Krishnan
Solution 3 Patel Pinkal
Solution 4