I have a list of users. Each user has a profile picture in storage that has a URL like this:
gs://my-app.appspot.com/users/uid.png
This list is displayed in a LazyRow:
LazyRow(
modifier = Modifier.fillMaxWidth()
) {
items(users) { user ->
LaunchedEffect(user.id) {
viewModel.getDownloadUrl(user.uid)
}
when(val response = viewModel.response) {
is Result.Loading -> Unit
is Result.Success -> {
user.downloadUrl = response.data
UserCard(
user = user
)
}
is Result.Failure -> print(response.e)
}
}
}
Since common libraries doesn't know how to read that reference, I need to convert to a real URL. So at each iteration, I create a call to get the download URL. The problem is that I get the same picture for all users and if scroll right, I get other pictures, but doubled, tripled. I don't understand why. How to overcome this situation?