将参数从 Flutter 传递到 Google Cloud Functions
Passing parameters from Flutter to Google Cloud Functions
我正在尝试弄清楚如何在 Flutter 和 Google Cloud Functions 之间进行通信。
我写了一个简单的 Google 云函数,其中 returns 一个列表和一个参数,但是当我使用参数调用该函数时,我一直收到空值。为什么会这样?
Flutter 函数
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"]
}
Google 云函数
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]
谁能帮我弄清楚为什么我的预期输出没有出现?
替换
final results = await callable.call(['hello']);
和
final results = await callable.call({text: 'hello'});
我正在尝试弄清楚如何在 Flutter 和 Google Cloud Functions 之间进行通信。 我写了一个简单的 Google 云函数,其中 returns 一个列表和一个参数,但是当我使用参数调用该函数时,我一直收到空值。为什么会这样?
Flutter 函数
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"]
}
Google 云函数
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]
谁能帮我弄清楚为什么我的预期输出没有出现?
替换
final results = await callable.call(['hello']);
和
final results = await callable.call({text: 'hello'});