【发布时间】:2020-01-02 19:13:05
【问题描述】:
不知道如何在 Flutter 中从云函数中获取响应。
我的云功能
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.testDemo = functions.https.onRequest((request, response) => {
return response.status(200).json({msg:"Hello from Firebase!"});
});
我的颤振代码
///Getting an instance of the callable function:
try {
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'testDemo',);
///Calling the function with parameters:
dynamic resp = await callable.call();
print("this is responce from firebase $resp");
} on CloudFunctionsException catch (e) {
print('caught firebase functions exception');
print(e.code);
print(e.message);
print(e.details);
} catch (e) {
print('caught generic exception');
print(e);
}
flutter:捕获到 firebase 函数异常 颤振:内部 颤振:响应缺少数据字段。 颤振:空
【问题讨论】:
-
您不能使用可调用函数 SDK 调用 HTTP 类型函数 (onRequest)。您将需要使用可调用类型函数 (onCall)。 firebase.google.com/docs/functions/callable
标签: firebase flutter dart google-cloud-functions