I'm trying to use the Functions Emulator but it is causing problems when I try to use it in my Flutter app. I am currently on the free plan, but I have read that Functions for Local Emulator are available.
When I create my function (using node v2) like this:
exports.getBooks = onRequest(async (req, res) => {
...
}
and then make an HTTP request from my browser, I get the desired result. However, when I change it to
const {onCall, onRequest} = require("firebase-functions/v2/https");
const logger = require("firebase-functions/logger");
const {getFirestore} = require("firebase-admin/firestore");
const admin = require("firebase-admin");
const app = admin.initializeApp();
const db = getFirestore(app);
exports.getBooks = onCall(async (request) => {
...
}
and then make the function call from my Flutter app, I get an UNAVAILABLE exception.
I have added the following code in my main.dart:
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);
and this code in my app:
final HttpsCallable getBooks = FirebaseFunctions.instance.httpsCallable('getBooks');
final response = await getBooks.call();
// OR without .call(): final response = await getBooks();
However, the .call()
method is causing the issue.
I have added android:usesCleartextTraffic="true"
to <application>
in my AndroidManifest.xml, but it does not resolve the issue.
Do you have any idea on how to make this work?
Related Links
[N/A]