firebasefluttergoogle-cloud-functions

Firebase Cloud Function: & Flutter: Cannot use https callable function on emulators [firebase_functions/unavailable] UNAVAILABLE


I'm trying to call a HTTPS callable function using emulators, from my flutter application, but it seems not to work. After I call the function, it always takes around 5 seconds and responds with an error. It works completely normal if I deploy the function on the server instead.

Here is my function

exports.try = functions.https.onCall((data, context) => {
  return 1;
});

It is located at us-central1

How I started the emulators

firebase emulators:start --only functions

How I called it from the code

FirebaseFunctions functions = FirebaseFunctions.instance;
functions.useFunctionsEmulator(origin: "http://10.0.2.2:5001");
HttpsCallable callable = functions.httpsCallable('games-oneToHundred-try');
try {
  var result  = await callable();
  print(result.data);
} catch (e) {
  print(e);
}

The error is thrown is:

[firebase_functions/unavailable] UNAVAILABLE

I modified the android manifest as suggested in Error connecting to local Firebase functions emulator from Flutter app like the following:

android:usesCleartextTraffic="true"

Solution

  • The problem was that my physical device cannot connect to localhost of my laptop. Using Android Emulator solved my problem