I have a function in my firebase class that returns the username when the UserID is provided to it.
fun getUserName(userID: String): String? {
var userName: String? = null
mFireStore.collection(Constants.USERS)
.whereEqualTo(Constants.ID, userID)
.get() // Will get the documents snapshots.
.addOnSuccessListener { document ->
for (i in document.documents) {
val user = i.toObject(User::class.java)!!
userName = user.userName
Log.e("userName", userName!!)
}
}
return userName
}
The function is not returning the username.
Although I am getting the correct username in the Log entry.