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?
2024 EDIT:
The cloud_functions
flutter package now supports calling 2nd gen functions by name, as you always could with 1st gen functions.
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 (the cloud_functions
package does not support using full URLs). You can use the dart http
package to do this, handling the request and response manually.