【问题标题】:Passing parameters from Flutter to Google Cloud Functions将参数从 Flutter 传递到 Google Cloud Functions
【发布时间】:2021-10-28 20:38:49
【问题描述】:

我正在尝试弄清楚如何在 Flutter 和 Google Cloud Functions 之间进行通信。 我编写了一个简单的 Google Cloud 函数,它返回一个列表和一个参数,但是当我使用参数调用该函数时,我一直收到 null。为什么会这样?

颤振函数

Future<void> getFruit() async {
   HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('listFruit');
   final results = await callable.call(['hello']);
   List fruit = results.data;
   print(fruit);// ["Apple", "Banana", "Cherry", "Date", "Fig", "Grapes"]
 }

谷歌云函数

const functions = require("firebase-functions");

exports.listFruit = functions.https.onCall((data, context) => {
  return ["Apple", "Banana", "Cherry", "Date", "Fig", "Grapes", data.text];
});

输出

flutter: [Apple, Banana, Cherry, Date, Fig, Grapes, null]

预期输出

flutter: [Apple, Banana, Cherry, Date, Fig, Grapes, hello]

谁能帮我弄清楚为什么我的预期输出没有出来?

【问题讨论】:

    标签: flutter dart google-cloud-firestore google-cloud-functions


    【解决方案1】:

    替换

    final results = await callable.call(['hello']);
    

    final results = await callable.call({text: 'hello'});
    

    【讨论】:

      猜你喜欢
      • 2021-10-03
      • 1970-01-01
      • 2019-03-10
      • 2018-04-22
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2023-01-24
      相关资源
      最近更新 更多