I have very simple code to just test Cloud Functions in my Flutter app together with Firestore Emulator. My Flutter code looks like this
CloudFunctions.instance.useFunctionsEmulator(origin: 'http://localhost:5005');
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'addNumbers',
);
dynamic resp = await callable.call(<String, dynamic>{});
my very basic function looks like this:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.addNumbers = functions.https.onCall((data) => {
return true;
});
and I get an error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(functionsError, Cloud function failed with exception., {code: INTERNAL, details: null, message: INTERNAL})
E/flutter (31009): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (31009): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter (31009): <asynchronous suspension>
E/flutter (31009): #2 MethodChannelCloudFunctions.callCloudFunction (package:cloud_functions_platform_interface/src/method_channel_cloud_functions.dart:43:15)
E/flutter (31009): #3 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:33:12)
Any ideas what might be the reason? There is no code or suggestion what might have happened. I've added Cloud Functions dependency to build.gradle, as well as google-services.json
Edit: Looks like the issue is with the emulator. I've deployed function to the server. Fixed the issues (wrong return type) and it worked.
The error is not with the emulator actually :
you are calling http://localhost:5005 when you run it in the emulator you have to change it to : 10.0.2.2 , so you can access localhost through emulator hope that helps .
10.0.2.2 = localhost
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With