问题描述
我尝试使用Firebase模拟器从Flutter应用程序中使用Firebase Cloud Functions。 在生产中,该调用工作正常,但在仿真器中却无法正常工作,我总是遇到以下错误。
[VERBOSE-2:ui_dart_state.cc(166)]未处理的异常:PlatformException(-5,操作无法完成。(com.google.GTMSessionFetcher错误-5。),空)
CloudFunctions(region: "europe-west3")
.useFunctionsEmulator(origin: "127.0.0.1:8080")
.getHttpsCallable(
functionName: "addUser",)
.call(
{"name": "oui","email": "[email protected]"},).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参数应为:
更改此实例以指向本地运行的Cloud Functions模拟器。
@param origin本地仿真器的起源,例如“ //10.0.2.2:5005”。
虽然不是很直觉,但我认为doc意味着功能仿真器。