Cloud Function return in a listview

Custom Code
Resolved

I'm creating a cloud function to search for candidates in relation to some filters for a vacancy, basically I'm searching in an array in my "cadvaga" collection for the "education" field and comparing it with the "Candidate" collection in the simple "education" field, if the candidate has one of the educations in the "cadvaga" array, I want to generate a list with the references of these candidates and show them in a listview, this function in the firebase console is already working and brings me the answer I want, the problem is in the treatment of this return in flutterflow.
I just can't do it.

This is my cloud function below (code), In this function I pass a parameter that is the reference of the vacancy and I also created its return as an array of type string

when calling the cloud function :

1- I update a page state of type string which is a list

2- then generate a listview of this page state

3- and in the listview I added text to show each item in the list

but only on firebase console on registers i can see the results like this:


const functions = require('firebase-functions');
const admin = require('firebase-admin');

if (admin.apps.length === 0) {
    admin.initializeApp();
}

exports.matchCandidatesToJob = functions.region('southamerica-east1')
    .runWith({
        memory: '128MB'
    }).https.onCall(async (data, context) => {
    const cadvagaReferencia = data.cadvagaReferencia;

    try {
        const db = admin.firestore();

        const jobDoc = await db.collection('cadvaga').doc(cadvagaReferencia).get();

        if (!jobDoc.exists) {
            console.log('Vaga não encontrada.');
            return { candidateRefs: [], message: 'Vaga não encontrada.' };
        }

        const jobData = jobDoc.data();
        const jobEscolaridade = jobData.escolaridade || [];

        const candidatesSnapshot = await db.collection('Candidato').get();

        const matchingCandidates = [];

        candidatesSnapshot.forEach((doc) => {
            const candidateData = doc.data();
            const candidateEscolaridade = candidateData.escolaridade;

            if (jobEscolaridade.includes(candidateEscolaridade)) {
                matchingCandidates.push(doc.ref.path);
            }
        });

        console.log('Candidatos correspondentes encontrados:', matchingCandidates);

        return { candidateRefs: matchingCandidates };
    } catch (error) {
        console.error('Erro ao buscar candidatos correspondentes:', error);
        throw new functions.https.HttpsError('unknown', 'Erro ao buscar candidatos correspondentes', error);
    }
}).catch(error => {
    console.error('Erro ao executar a função:', error);
});
What have you tried so far?

I have already tried
#1 - to change the return that is like this in the function;

return { candidateRefs: matchingCandidates };

to just return me a list of strings

like this:
return { candidateRefs: matchingCandidates };

#2 - I tried changing the local state return to a list JSON data type, just JSON and nothing.

#3 - I've also tried to create a data type with a candidate field of type string and an app state calling this data type to save the list there and it didn't work either.

If there is any kind soul who can help me I would be very grateful.

Did you check FlutterFlow's Documentation for this topic?
Yes
3
4 replies