Flutter - 区域不工作的 Firebase 可调用函数
Flutter - Firebase callable functions with region not working
我们目前在我们的 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>
据我们测试,如果我们根据 docs:
定义 flutter 中的区域,则没有任何区别
final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
或者直接在云函数中:
exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
// ... return result
});
如果我们删除上面两行中的区域,则可调用函数正在运行并返回预期结果。
有什么我想念的,或者目前 flutter 本身有问题吗?
经过一些测试和 Peter Koltai 的评论后,解决方案是在 flutter 和 cloud 函数中定义区域:
颤振:
final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
云函数:
exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
// ... return result
});
当然,这是有道理的,因为作为调用者,我想调用“europe-west1”区域之外的可调用函数。如果需要,这可以灵活地为不同的区域调用不同的函数。
我们目前在我们的 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>
据我们测试,如果我们根据 docs:
定义 flutter 中的区域,则没有任何区别final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
或者直接在云函数中:
exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
// ... return result
});
如果我们删除上面两行中的区域,则可调用函数正在运行并返回预期结果。
有什么我想念的,或者目前 flutter 本身有问题吗?
经过一些测试和 Peter Koltai 的评论后,解决方案是在 flutter 和 cloud 函数中定义区域:
颤振:
final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
云函数:
exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
// ... return result
});
当然,这是有道理的,因为作为调用者,我想调用“europe-west1”区域之外的可调用函数。如果需要,这可以灵活地为不同的区域调用不同的函数。