I’m trying to call my Firebase gen2 function from my Flutter app, however my cloud function can’t read the data sent to it nor pass it forward.
Here’s my Flutter function:
Future<bool> _test() async {
final httpCallable = FirebaseFunctions.instance
.httpsCallableFromUrl(cloudFunctionsVerifyPurchase); // a valid url
final data = <String, dynamic>{
'dataKey1': 'dataValue1',
'dataKey2': 'dataValue2',
};
final res = await httpCallable.call(data);
print(res.data);
return false;
}
Here’s my cloud function:
exports.test = onCall(async(data,context) => {
// Access the data sent from the Flutter app
const dataValue1 = data.dataKey1; // null
const dataValue2 = data.dataKey2; // null
// when I console.log(data) I get a massive object, and not the object I sent. I tried doing data.body but that also returns null
return {
message: dataValue1,
result: dataValue2,
};
});
My Cloud Function Logs (You can see that ‘dataKey1’ & ‘dataKey2’ exist!):
>Solution :
The signature of the onCall() method has changed with Cloud Functions 2nd gen: You now need to pass a unique request parameter which "contains data passed from the client app as well as additional context like authentication state" as explained in the doc.
So you need to adapt your code as follows:
exports.test = onCall(async(request) => {
// Access the data sent from the Flutter app
const dataValue1 = resquest.data.dataKey1; // null
const dataValue2 = request.data.dataKey2; // null
//...

