Javascript 为什么我的云函数不能正确返回地图?

Javascript 为什么我的云函数不能正确返回地图?,javascript,firebase,flutter,dart,google-cloud-functions,Javascript,Firebase,Flutter,Dart,Google Cloud Functions,我有以下功能,我正在尝试将一系列地图返回到我的颤振应用程序 export const usersFromContacts = functions.region('europe-west1').https.onCall(async (data, context) => { Authentication.authenticate(context); const phonenumbers = Validator.validateArray<string>('phone

我有以下功能,我正在尝试将一系列地图返回到我的颤振应用程序

export const usersFromContacts = functions.region('europe-west1').https.onCall(async (data, context) => {
    Authentication.authenticate(context);
    const phonenumbers = Validator.validateArray<string>('phonenumbers', data['phonenumbers']);

    const privateDataPromises = [];
    for (let i = 0; i < phonenumbers.length; i++)
        privateDataPromises.push(...(await firestore.collectionGroup('userPrivateData')
            .where('phonenumber', '==', phonenumbers[i]).get()).docs);
    const userSnapshots = await Promise.all(privateDataPromises);

    const userPromises = [];
    for (let i = 0; i < userSnapshots.length; i++) {
        const userID = privateDataPromises[i].id;
        userPromises.push(userCollection.doc(userID).get());
    }

    const returnValue = (await Promise.all(userPromises)).map((document) => UserModel.fromFirestoreDocumentData(document).toMap());
    console.log(returnValue);
    return returnValue;
});
是我在firebase函数控制台中得到的。在这里,我替换了ofc的值

然后在我的内心颤栗

  Future<HttpsCallableResult> _callCloudFunction(String functionName, {Map<String, dynamic> data}) async {
    final cloudFunction = api.getHttpsCallable(functionName: functionName);
    try {
      final httpCallable = await cloudFunction.call(data).timeout(Duration(seconds: timeout));
      print(httpCallable.data); // this prints [{}] an empty array of maps?
      return httpCallable;
    } on CloudFunctionsException catch (error) {
      throw new UserFriendlyException(error.code, error.message);
    } on TimeoutException catch (error) {
      throw new UserFriendlyException('Operation Failed', error.message);
    } catch (error) {
      throw new UserFriendlyException('Operation Failed', 'There was a problem with with executing the operation');
    }
  }
我得到一个空的地图数组?我做错了什么


我很确定这个调用是正确的,因为如果我直接返回文档,我确实会在前端得到它们,那么我是否以错误的方式从函数返回值?

您正在尝试将ES6映射对象从函数序列化到客户端。这不是你想要的方式

云函数可调用函数仅支持序列化普通JavaScript对象、数组和基元值。传递一个普通的JS对象,而不是传递一个贴图。这是您必须更改的代码:

UserModel.fromFirestoreDocumentData(document).toMap()
您必须进入toMap函数内部并对其进行更改,或者将其输出转换为普通JS对象以进行序列化

UserModel.fromFirestoreDocumentData(document).toMap()