I get data from the api in Jetpack Compose but when I try to display it in LazyRow nothing is displayed whereas when I manually feed it, it works fine.
LazyRow(
contentPadding = PaddingValues(horizontal = 20.dp),
horizontalArrangement = Arrangement.spacedBy(15.dp)
) {
professorViewModel.getByUniversityName("universityName") { response ->
if (response.status == "OK") {
val professorList = response.data!!
//During debugging, I see that this list
//is correctly filled with two items
//and the information is taken from the api and its status is ok.
items(professorList.size) {
val professor = professorList[0]
ProfessorItem(professor) //function to show each item
}
}
}
}
That will show just the first thing because it always shows the element of index 0. A better way to do this is :
LazyRow(
contentPadding = PaddingValues(horizontal = 20.dp),
horizontalArrangement = Arrangement.spacedBy(15.dp)
) { professorViewModel.getByUniversityName("universityName") { response ->
if (response.status == "OK") {
val professorList = response.data!!
//During debugging, I see that this list
//is correctly filled with two items
//and the information is taken from the api and its status is ok.
items(professorList) {professor->
ProfessorItem(professor)
}
}
}
}
Make sure that you're importing the right items
function because there is two one that takes Int
as parameter and one that takes List
as parameter so you import the last one