Ste*_*ann 6 firebase flutter google-cloud-functions
目前,我们的 flutter 应用程序面临着一个问题,即使用区域定义的 httpsCallable 函数(在我们的示例中为“europe-west1”)会抛出异常:
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_functions/internal] Response is not valid JSON object.
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
<asynchronous suspension>
#2 MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:23:24)
<asynchronous suspension>
#3 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:35:37)
<asynchronous suspension>
#0 MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:39:7)
<asynchronous suspension>
#1 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:35:37)
<asynchronous suspension>
Run Code Online (Sandbox Code Playgroud)
到目前为止,根据我们的测试,如果我们根据docs定义 flutter 中的区域,则没有什么区别:
final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
Run Code Online (Sandbox Code Playgroud)
或者直接在云函数中:
exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
// ... return result
});
Run Code Online (Sandbox Code Playgroud)
如果我们删除上面两行中的区域,则可调用函数将正常工作并返回预期结果。
有什么东西,我错过了什么,或者颤振本身目前存在问题吗?
经过一些测试和 Peter Koltai 的评论后,解决方案是在 flutter 和云函数中定义区域:
扑:
final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
Run Code Online (Sandbox Code Playgroud)
云功能:
exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
// ... return result
});
Run Code Online (Sandbox Code Playgroud)
当然,这是有道理的,因为作为调用者,我想从“europe-west1”区域调用可调用函数。如果需要,这可以灵活地为不同区域调用不同的函数。
| 归档时间: |
|
| 查看次数: |
1156 次 |
| 最近记录: |