问题
Since the version 0.2.0 cloud_functions for Flutter use .getHttpsCallable() instead of .call(). The new method is defined as:
/// @param functionName The name of the callable function being triggered.
/// @param parameters Parameters to be passed to the callable function.
HttpsCallable getHttpsCallable(
{@required String functionName, Map<String, dynamic> parameters}) {
return HttpsCallable._(this, functionName);
}
As we can see, the argument parameters is not used though declared and documented (I learned it the hard way while debugging the app.) So, one is expected to pass the parameters to the subsequent .call() on the callable object. What's the reason why the argument is declared for the new method at all?
回答1:
Although I can't explain why it was designed this way, some people might find this post looking for help using the getHttpsCallable function. Here is an example calling a cloud function called addUser with two parameters, email and password. These parameters would normally be defined in another way such as via the text property of a TextController.
CloudFunctions.instance.getHttpsCallable(
functionName: "addUser",
).call(
<String, dynamic>{
"email": "test@test.com",
"password": "Terrific password!"
},
);
回答2:
I also wondered why but it does make for cleaner code at least:
HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'myFunction',
);
try {
HttpsCallableResult response = await callable.call(<String, dynamic>{
'firstParam': firstParam,
'secondParam': secondParam,
});
} catch (e) {
// ...
}
来源:https://stackoverflow.com/questions/56112544/cloudfunctions-gethttpscallable-parameters