'Flutter - Firebase cloud function callable functions wrong format

I'am trying to modify my firestore database with a callable function from cloud function... Here is my cloud function:

exports.addUserDisplayName = functions.region("europe-west1")
    .https.onCall((data, context) => {
      functions.logger.log("User displayname updated",
          data.userUid, data.displayName);
      admin.firestore().collection("users").doc(data.userUid).update({
        displayName: data.displayName,
      });
      return {
        status: "done",
      };
    });

And here is my call of this cloud function on my flutter app:

HttpsCallable addUserDisplayName = FirebaseFunctions.instance.httpsCallable("addUserDisplayName");
      await addUserDisplayName.call({
        'userUid': userCredential!.user!.uid,
        'displayName': "$firstName $lastName",
      },);

But I don't know why, every time I try to call my function, I get this error and nothing is called :

flutter: [firebase_functions/3840] The data couldn’t be read because it isn’t in the correct format.

#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
<asynchronous suspension>
#2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:22:24)
<asynchronous suspension>
#3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:34:37)
<asynchronous suspension>
#4      AuthProvider.createUser (package:kcount/providers/auth_provider.dart:50:7)
<asynchronous suspension>

Do you have any idea why ?



Solution 1:[1]

This can also happen if you do not export the function in the index. Make sure that the function is available in the Firebase function/dashboard.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marian