Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

330
Vistas
Flutter - Return Null value while using Http Request in Cloud Functions

Here is my issue, I have a callable Cloud Function I would like to use on my Flutter app.

You can find the code below.

However, each time I press the button corresponding to the function I always have a "null" value on my app coming from Cloud Functions even if my answer is printed into the console.

From what I understand, the function return a "null" value as the jsonResponse is not here yet.

I would like to find a way to return the jsonResponse only when the answer is there.

I tried async, await, and promises already, but maybe I used it the wrong way ?

Thank you


// code on JS

exports.writeMessage = functions.https.onCall(async (data, context) => {

  global.XMLHttpRequest = require("xhr2");
  function makeRequest(method, url) {
    appleMusicKey = 'XXXXXXX'
    return new Promise(function (resolve, reject) {
      let http = new XMLHttpRequest();
      http.open(method, url);
      http.setRequestHeader('Authorization', 'Bearer ' + appleMusicKey);
      http.onload = function () {
        if (this.status >= 200 && this.status < 300) {
          resolve(JSON.parse(http.response)['data'][0]['attributes']['url'].toString());
        } else {
          reject({
            status: this.status,
            statusText: http.statusText
          });
        }
      };
      http.onerror = function () {
        reject({
          status: this.status,
          statusText: xhr.statusText
        });
      };
      http.send();
    });
  }

  async function doAjaxThings() {
    var isrcCode = 'QMBZ92168114';
    let result = await makeRequest("GET", `https://api.music.apple.com/v1/catalog/fr/songs?filter[isrc]=${isrcCode}`);
    
    console.log(result);

    return new Promise(function (resolve, reject) {
      resolve(result);
      reject('error');
    });
  }

  doAjaxThings();

});

// code on Flutter for calling the function

  Future<void> writeMessage(
  ) async {
    HttpsCallable callable =
        FirebaseFunctions.instance.httpsCallable('writeMessage');
    final resp = await callable.call();
    print(resp.data);
  }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda