A continuación se muestra el error que recibo. Vi un tutorial y el desarrollador tenía exactamente el mismo código y funcionó en su extremo, no sé qué estoy haciendo mal. Estoy usando la plataforma getstream.io a través del paquete stream_chat_flutter_core.
Response is not valid JSON object. I/flutter ( 8805): I/flutter ( 8805): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7) I/flutter ( 8805): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18) I/flutter ( 8805): <asynchronous suspension> I/flutter ( 8805): #2 MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:23:24) I/flutter ( 8805): <asynchronous suspension> I/flutter ( 8805): #3 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:49:37) I/flutter ( 8805): <asynchronous suspension> I/flutter ( 8805): #4 FirebaseService.joinWithEmailAndPassword (package:thrills/util/firebase_service.dart:357:25) I/flutter ( 8805): <asynchronous suspension> I/flutter ( 8805): #5 _JoinState.build.<anonymous closure> (package:thrills/screens/join/join.dart:285:33) I/flutter ( 8805): <asynchronous suspension>A continuación se muestra la función de nube que uso en firebase
const StreamChat = require('stream-chat').StreamChat; const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(); const serverClient = StreamChat.getInstance(functions.config().stream.key, functions.config().stream.secret); exports.createStreamUserAndGetToken = functions.region("us-west2").https.onCall(async (data, context) => { // Checking that the user is authenticated. if (!context.auth) { // Throwing an HttpsError so that the client gets the error details. throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' + 'while authenticated.'); } else { try { // Create user using the serverClient. await serverClient.upsertUser({ id: context.auth.uid, name: context.auth.token.name, email: context.auth.token.email, image: context.auth.token.image, }); // Create and return user auth token. return serverClient.createToken(context.auth.uid); } catch (err) { console.error(`Unable to create user with ID ${context.auth.uid} on Stream. Error ${err}`); // Throwing an HttpsError so that the client gets the error details. throw new functions.https.HttpsError('aborted', "Could not create Stream user"); } } });Y finalmente, así es como llamo a la función y recupero los datos.
final callable = FirebaseFunctions.instance .httpsCallable('createStreamUserAndGetToken'); final results = await callable(); some random code... (results.data is only used once as an argument to some function) results.data as String