I have a list of strings where I store network images that I later iterate through within a forEach loop, and within it, I have the GlideImage composable that allows me to determine if the image was loaded correctly. However, when I add a variable to track how many images were loaded correctly, the counter never stops.
fun ImageLoader() {
val urls = listOf(
"https://www.example.com/image1.jpg",
"https://www.example.com/image2.jpg",
"https://www.example.com/image3.jpg",
"https://www.example.com/image1.jpg",
)
val successfulImageCount = remember { mutableStateOf(0) }
Column(modifier = Modifier.fillMaxSize()) {
urls.forEach { url ->
GlideImage(
imageModel = { url },
success = { status: GlideImageState.Success, image: Painter ->
successfulImageCount.value++
Image(painter = image, contentDescription = "")
},
modifier = Modifier.size(80.dp),
)
}
Text(text = "Images uploaded correctly: ${successfulImageCount.value}")
}
}