I'm trying to update a composable using mutableState inside a loop, but it only updates to the last value, after the loop finishes:
In Main.kt
@Composable
fun App() {
var myClass = remember { MyClass() }
MaterialTheme {
Column() {
Text(text="${myClass.myInt.value}")
Button(onClick = myClass::run){ Text(text = "RUN") }
}
}
}
where
class MyClass {
val myInt = mutableStateOf(0)
fun run(){
for (i in 0..10){
myInt.value = i
Thread.sleep(500)
}
}
}
what am I missing? (I'm using Compose Desktop)