Tengo una aplicacion, y estoy intentando recuperar una lista de productos desde cloud firestore. El codigo:
private var foodPetitions2: MutableList<FoodPetition> = mutableListOf()
private var adapter = FoodAdapter2(foodPetitions2, this)
private var db = FirebaseFirestore.getInstance()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_category_products)
val bundle = intent.extras
val docs = db.collection("productos").whereEqualTo("category", bundle?.get("category"))
docs.get().addOnSuccessListener {
for (document in it){
addItem(FoodPetition(document.data["name"] as String, document.data["image"] as String, document.data["id"] as String))
}
addItem(FoodPetition("s", "a", "asdas"))
}
foodPetitions2.forEach{
println(it.name)
println(it.image)
println(it.id)
}
setup()
}
El problema es que los cambios a variables que hago dentro del addOnSuccessListener no se guardan, y no entiendo por que.