https://kotlinlang.org logo
Title
i

Ink

04/28/2022, 10:04 PM
Hi! I'm having troubles with displaying photos in
HirozontalPager()
It always displays the same photo.
product.photos
is a List<String> with different links to photos.
HorizontalPager(
    count = product.photos.size,
    state = pagerState,
) {
    product.photos.forEach { photoUrl ->
        Image(
            painter = rememberAsyncImagePainter(photoUrl),
            modifier = Modifier
                .height(150.dp)
                .fillMaxWidth(),
            contentScale = ContentScale.Fit,
            contentDescription = ""
        )
    }
}
m

myanmarking

04/28/2022, 10:08 PM
I think horizontalPager lambda has an index that you must use to get the list item. Drop the forEach
👍 2
i

Ink

04/28/2022, 10:19 PM
Yeah, you're right. Thanks!