0

Like title said it needs to update image with new picture in Android Compose, using Coil.

 AsyncImage(
        model = URL,
        contentDescription = "",
        modifier = Modifier.clickable(onClick = {
            //Maybe here to add code?
        })
    )

What I need is to load new picture from link into existing AsyncImage.

acakojic
  • 306
  • 2
  • 11

1 Answers1

1

Create a mutable state that you update with new url:

var model by remember { mutableStateOf(URL) }
AsyncImage(
    model = model,
    contentDescription = "",
    modifier = Modifier.clickable(onClick = {
        model = newUrl
    })
)
Jan Bína
  • 3,447
  • 14
  • 16
  • This is working when I got different URL. I'm trying to figure out how to work with same URL. Let me be more clear with example: When I click URL i got Random picture, and everytime I get diferent picture. This is the problem that I'm facing. One URL get Random pictures but it wont work in this code: here is the link: https://cataas.com/cat try to refresh and you will see that it returns random pictures. – acakojic May 09 '23 at 17:25
  • This is not working: onClick = { model = URL }) – acakojic May 09 '23 at 17:33
  • I will create another question that is with same URL. Your answer is correct it works with new URL. – acakojic May 09 '23 at 17:44