firebase - Flutter + Firebase Cloud Functions - 如何从 HttpsCallableResult 获取数据

标签 firebase flutter google-cloud-functions

我编写了一个简单的云函数,它返回一个保存在我的 Cloud Firestore 数据库中的 ID。

云函数如下所示:


exports.getWinkert = functions.https.onCall((data, context) => {

    return admin.firestore().collection('users').doc('hash').get()
    .then(snapshot => {
        const winkertId = snapshot.wwinkert
        return { id: winkertId };
    })
})

此函数是使用以下代码从我的 flutter 应用中调用的:


Future _getValues() async {
    final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
      functionName: "getWinkert",
    );
    dynamic resp = await callable.call(<String, dynamic>{
      "name": "wwinkert",
    });
    print(resp.toString());
  }

调用该函数后,我得到了这个结果:

I/flutter ( 8253): Instance of 'HttpsCallableResult'

问题:如何从 Dart 中的 HttpsCallableResult 实例获取数据?

提前感谢您的帮助!

您好, 劳尔

最佳答案

快速浏览此文档:

https://github.com/flutter/plugins/tree/master/packages/cloud_functions

表明可以通过将 .data 添加到 HttpsCallableResult 对象来获取数据。

. . .

我很抱歉:D

关于firebase - Flutter + Firebase Cloud Functions - 如何从 HttpsCallableResult 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56400220/

相关文章:

swift - 如何正确使用queryOrderedByValue

android - 是否可以序列化和反序列化包含对象作为 Firebase 中的变量的对象?

android-studio - Flutter build.gradle麻烦

javascript - Firebase 云函数抛出关于 "timestampsInSnapshots"的警告

firebase - googlesheet文档的状态变化可以触发云函数吗?

python-3.x - Google Cloud Functions 未返回响应

firebase - 如何仅在 Sapper 的客户端上导入 Firebase?

android - 通过电子邮件和密码使用 firebase 注册用户?

javascript - 解决 Cloud Functions 中未定义的 "TypeError: Cannot read property ' 数据'

dart - json.decode 之后的空检查