KotlinLeaner
02/01/2023, 11:21 AMStateful and Stateless with some code, but it have some problem to increment the value. Can you guys guide me on this.KotlinLeaner
02/01/2023, 11:21 AM@Composable
fun ItemColorStateful() {
var index by remember { mutableStateOf(-1) }
Column(modifier = Modifier.fillMaxSize()) {
Text(text = "Different Color")
ButtonScopeStateless(
index = { index },
onIndexChange = {
index = it
}
)
}
}
ButtonScopeStateless
@Composable
fun ButtonScopeStateless(
index: () -> Int,
onIndexChange: (Int) -> Unit,
) {
Button(onClick = { onIndexChange(index()++) }) {
Text(text = "Click Me $index")
}
}KotlinLeaner
02/01/2023, 11:21 AMStylianos Gakis
02/01/2023, 11:43 AMindex() + 1. You can’t increment a parameter which is immutable, as that’s what ++ is trying to do.KotlinLeaner
02/01/2023, 11:43 AMKotlinLeaner
02/01/2023, 12:17 PMButtonScopeStateless on the first parameter should I use index: () -> Int, or index: Int . Which one is good in my conditon?Stylianos Gakis
02/01/2023, 12:22 PMKotlinLeaner
02/01/2023, 12:33 PM