不知道如何在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!"});
});
我的Flutter 代码
///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函数异常