I want to return an element from the function but I get the error "lateinit property policlinic has not been initialized". By the way, when I try to write to the Toast message, data comes in successfully.
private lateinit var policlinic: String
private fun useranddoctor(): String{
val collection = Firebase.firestore.collection("users")
collection.get()
.addOnSuccessListener { documentSnapshot ->
for (document in documentSnapshot) {
if (document.getString("kullaniciseviyesi") == "1" && document.getString("email") == firebaseAuth.currentUser?.email) {
policlinic = document.getString("policlinic")!!
}
}
}.addOnFailureListener {
}
return policlinic
}
CodePudding user response:
private var policlinic: String? = null
private fun useranddoctor(): String{
val collection = Firebase.firestore.collection("users")
collection.get()
.addOnSuccessListener { documentSnapshot ->
for (document in documentSnapshot) {
if (document.getString("kullaniciseviyesi") == "1" && document.getString("email") == firebaseAuth.currentUser?.email) {
policlinic = document.getString("policlinic")!!
}
}
}.addOnFailureListener {
}
return policlinic
}