如何解决flutter firebase 云函数模拟器,调用函数不起作用
我使用 firebase 模拟器,但我的云功能出错...
我这样调用我的函数:
HttpsCallable displayNameAndEmail = FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable("displayNameAndEmail");
displayNameAndEmail.call({
'displayName': "$firstName $lastName",'lang': lang,'email': email
});
print("\nDisplayName6\n\n");
这是我得到的错误:
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: [firebase_functions/unavailable] UNAVAILABLE
E/flutter (14049):
E/flutter (14049): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
E/flutter (14049): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
E/flutter (14049): <asynchronous suspension>
E/flutter (14049): #2 MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:22:24)
E/flutter (14049): <asynchronous suspension>
E/flutter (14049): #3 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:34:37)
E/flutter (14049): <asynchronous suspension>
E/flutter (14049):
E/flutter (14049): #0 MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:38:7)
E/flutter (14049): <asynchronous suspension>
E/flutter (14049): #1 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:34:37)
E/flutter (14049): <asynchronous suspension>
E/flutter (14049):
有什么想法吗?
解决方法
第一行创建一个单独 FirebaseFunctions 实例(针对指定区域)。正如 Frank 在第一条评论中指出的那样,您必须指示这个新实例连接到模拟器。
Here 是 FlutterFire 文档,提供了更多详细信息。如果您使用的是 Android:
- 记得使用
10.0.2.2
作为主机(使用 Android 模拟器时需要) - 添加
<application android:usesCleartextTraffic="true"/>
到android\app\src\debug\AndroidManifest.xml
。这允许进出 Firebase 模拟器的纯 HTTP 流量。
另一个有用的提及是利用 dart cascade notation,..
,如下所示:
String ip = Platform.isAndroid ? '10.0.2.2' : 'localhost';
var instance = FirebaseFunctions.instanceFor(region: 'europe-west1')
..useFunctionsEmulator(origin: 'http://$ip:5001');
HttpsCallable displayNameAndEmail =
instance.httpsCallable("displayNameAndEmail");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。