未找到方法:'guard'。 return internals.guard(

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

我是新手 flutter.when 我 运行 flutter web 上的这段代码发生了这个错误。 .pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-1.0.7/lib/src/internals.dart:10:20:

有人帮助解决问题

如果您将 flutter sdk 更新到 Beta 通道,请将您的 flutter sdk 降级到稳定通道。当前稳定版本为 2.10.3

Flutter downgrade command

flutter downgrade v2.10.3

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 

将以上软件包添加到更新版本的 pubspec.yaml 文件中

以下对我有用:

我升级了:

firebase_core:^1.0.4 至 firebase_core:^1.13.1

cloud_firestore:^1.0.6 至 cloud_firestore:^3.1.10

firebase_analytics: ^9.1.0 -> firebase_analytics: ^9.1.2

然后做:

颤动干净

颤动运行

参考:https://github.com/firebase/flutterfire/issues/8194 欲了解更多信息

cloud_firestore: ^3.1.13 
cloud_firestore_web: ^2.6.13

将以上软件包添加到您的 pubspec.yaml 文件

您可以将所有 firebase 软件包升级到可用的最新版本(主要是 firebase_core 到最新版本),或者您可以修改我们为 internals 得到的错误,如下所示:

Step-1:打开你遇到错误的firebase包的internals.dart文件。

第 2 步: 将函数使用从 internals.guard() 更改为 internals.guardWebExceptions(),如下所示:

发件人:

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

收件人:

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.