it inside the . addSuccessListener

Asked

Viewed 21 times

-2

I’m using Firestore for a project where I do a user query, however this giving problem when I get the "it" object inside the method. addOnSuccessListener, no it.name an Unresolved Reference error appears:

var firebaseFirestore = FirebaseFirestore.getInstance()
        firebaseFirestore.collection("Usuarios").document(evento.host!!).get()
            .addOnSuccessListener {
                txt_nome_evento_exibir.setText(evento.nome)
                txt_data_evento_exibir.setText(evento.data)
                txt_descricao_evento_exibir.setText(evento.descricao)
                txt_local_evento_exibir.setText(evento.local)
                txt_host_evento_exibir.setText(it.nome)
                txt_horario_evento_exibir.setText(evento.horario_inicio)
            }

1 answer

0


You are giving this problem because "it" is a Documentsnapshot, you have to turn it into an object:

var firebaseFirestore = FirebaseFirestore.getInstance()
        firebaseFirestore.collection("Usuarios").document(evento.host!!).get()
            .addOnSuccessListener {
                var aux = it.toObject(SeuObjeto::class.java)
                txt_nome_evento_exibir.setText(evento.nome)
                txt_data_evento_exibir.setText(evento.data)
                txt_descricao_evento_exibir.setText(evento.descricao)
                txt_local_evento_exibir.setText(evento.local)
                txt_host_evento_exibir.setText(aux!!.nome)
                txt_horario_evento_exibir.setText(evento.horario_inicio)
            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.