I have a Flutter app that uses cloud functions. I upgraded one function to a v2 function and it no longer works. The function cannot be found. The function logs do not show that it is being called. It is in the us-central1
region, as is the rest of the project.
final result = await FirebaseFunctions.instance.httpsCallable('addMessage').call();
Instead of addMessage
I have tried the full function URL found in the firebase console, but that does not work either.
Function declaration:
exports.addMessage = onCall(async (request) => {
//Run function
});
How do I call a v2 cloud function in flutter?
2
Answers
Conclusion: as of now you cannot call a v2 cloud function using the flutter
cloud_functions
package. You must use a regular http request to the full function URL (thecloud_functions
package does not support using full URLs). You can use the darthttp
package to do this, handling the request and response manually.With
cloud_functions
version 4.1.0, it is now possible to call 2nd gen cloud functions:Note that you need to deploy the function before you can know what the URL will be. This will change in the future according to the docs:
https://cloud.google.com/functions/docs/tutorials/http#triggering_the_function