I'm developing an Android app with Kotlin, and I want to fill the Customer data class I've created with values from Firebase.
It's impossible to return from an .addOnCompleteListener after .get, therefore, I can't just return Customer, which would be ideal. I've read about toObject, but am not sure how to correctly use it (or if it does solve my problem).
Customer.kt:
data class Customer (
val name: String,
val phone: String,
val address: String,
val lastVisit: String,
val lastVisitTimestamp: Timestamp,
val latitude: Double,
val longitude: Double
) : Serializable
Pseudo-code for what I want to achieve:
ref.whereEqualTo("name", name)
.get()
.addOnCompleteListener { task ->
val name = task.result?.documents!![0].data!!["name"].toString()
val customer = Customer()
customer.name = name
// I want to return this customer object. That's what I can't do.
return Customer()
}
// and so on