简体   繁体   English

Flutter - Firebase 区域不工作的可调用函数

[英]Flutter - Firebase callable functions with region not working

we currently facing the problem in our flutter app, that httpsCallable functions which are defined with a region, in our case "europe-west1", is throwing an exception:我们目前在我们的 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>

As far, as we tested, it makes no difference, if we define the region in flutter accordingly to docs :就我们测试而言,如果我们根据文档在 flutter 中定义区域,则没有任何区别:

final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();

Or directly in the cloud function:或者直接在云端function:

exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
   // ... return result
});

If we remove the region on both lines above, the callable function is working and returning the expected result.如果我们删除上面两行中的区域,则可调用 function 正在运行并返回预期结果。

Is there something, what I miss or is there currently an issue in flutter itself?有什么我想念的,或者 flutter 本身目前有问题吗?

After some testing and the comment from Peter Koltai, the solution is defining the region in both, flutter and cloud functions:经过一些测试和 Peter Koltai 的评论后,解决方案是在 flutter 和云函数中定义区域:

flutter: flutter:

final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();

cloud functions:云功能:

exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
   // ... return result
});

Of course, this makes sense, because as the caller, I want to call the callable functions out of the "europe-west1" region.当然,这是有道理的,因为作为调用者,我想调用“europe-west1”区域之外的可调用函数。 This gives, if required, the flexibility to call different functions for different regions.如果需要,这可以灵活地为不同的区域调用不同的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM