Flutter - Firebase 云函数可调用函数格式错误

Flutter - Firebase cloud function callable functions wrong format

我正在尝试使用来自云函数的可调用函数修改我的 firestore 数据库...这是我的云函数:

exports.addUserDisplayName = functions.region("europe-west1")
    .https.onCall((data, context) => {
      functions.logger.log("User displayname updated",
          data.userUid, data.displayName);
      admin.firestore().collection("users").doc(data.userUid).update({
        displayName: data.displayName,
      });
      return {
        status: "done",
      };
    });

下面是我在我的 flutter 应用程序上调用这个云函数:

HttpsCallable addUserDisplayName = FirebaseFunctions.instance.httpsCallable("addUserDisplayName");
      await addUserDisplayName.call({
        'userUid': userCredential!.user!.uid,
        'displayName': "$firstName $lastName",
      },);

但我不知道为什么,每次我尝试调用我的函数时,都会出现此错误并且没有调用任何内容:

flutter: [firebase_functions/3840] The data couldn’t be read because it isn’t in the correct format.

#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
<asynchronous suspension>
#2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:22:24)
<asynchronous suspension>
#3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:34:37)
<asynchronous suspension>
#4      AuthProvider.createUser (package:kcount/providers/auth_provider.dart:50:7)
<asynchronous suspension>

你知道为什么吗?

好的,我发现问题出在区域上...我忘了把 .instanceFor(region: 'europe-west1')

所以我必须这样做:

HttpsCallable addUserDisplayName = FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable("addUserDisplayName");
      await addUserDisplayName.call({
        'userUid': userCredential!.user!.uid,
        'displayName': "$firstName $lastName"
      },);

而不是:

HttpsCallable addUserDisplayName = FirebaseFunctions.instance.httpsCallable("addUserDisplayName");
      await addUserDisplayName.call({
        'userUid': userCredential!.user!.uid,
        'displayName': "$firstName $lastName",
      },);

如果您不导出索引中的函数,也会发生这种情况。确保该函数在 Firebase function/dashboard.

中可用