skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. With cloud_functions version 4.1.0, it is now possible to call 2nd gen cloud functions:

    FirebaseFunctions.instance
          .httpsCallableFromUrl("https://example.run.app/")
          .call({"paramter": "value"});
    

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search