Flutter:在 Firebase 模拟器上调用 Firebase Cloud Function 时发生 PlatformException

Flutter: PlatformException when calling Firebase Cloud Function on Firebase Emulator

我尝试通过 Firebase 模拟器从我的 Flutter 应用程序中使用 Firebase Cloud Functions。 在生产中,调用工作正常,但在 Emulator 中却不行,我总是收到以下错误。

调用函数后出错

[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: PlatformException(-5, The operation couldn’t be completed. (com.google.GTMSessionFetcher error -5.), null)

Flutter代码

CloudFunctions(region: "europe-west3")
              .useFunctionsEmulator(origin: "127.0.0.1:8080")
              .getHttpsCallable(
                functionName: "addUser",
              )
              .call(
            {"name": "oui", "email": "oui@oui.fr"},
          ).then(
            (value) {
              print('OK');
              print(value);
            },
          );

firebase.json

{
  "emulators": {
    "functions": {
      "port": 5001
    },
    "firestore": {
      "host": "0.0.0.0",
      "port": 8080
    },
    "ui": {
      "enabled": true
    }
  }
}

firebase.json 函数模拟器端口设置为 5001,而在提供的代码中 useFunctionsEmulator 方法调用 8080。此端口设置为 firestore 模拟器。

根据documentation参数应该是:

Changes this instance to point to a Cloud Functions emulator running locally.

@param origin The origin of the local emulator, such as "//10.0.2.2:5005".

虽然不是直的,但我想文档的意思是函数模拟器。