Michael Friend
07/30/2023, 6:08 PMmutableStateListOf
and Checkbox
that I’m pretty sure is a bug with Checkbox, was wondering if anyone has run into this and found a good workaround.
So i have a Column of CheckBoxes
and I’m using a SnapshotStateList<Boolean>
to track the checked state of all the checkboxes. For some reason any checkbox that starts with checked=true
works fine but if the initial value is false then its stuck in this weird in sort of disabled state and doesnt change despite the state updating. Heres a code snippet
@Composable
fun CheckList() {
val checked: MutableList<Boolean> = remember {
mutableStateListOf(false, false, true, false, true, true, false)
}
Column {
(0..6).forEach { index ->
Row(verticalAlignment = Alignment.CenterVertically) {
// Only the ones that start true work right
Checkbox(checked = checked[index], onCheckedChange = { checked[index] = it })
// The color of these update as expected when the checkbox is clicked so the state is updating properly
Icon(
Icons.Default.CheckCircle,
contentDescription = null,
tint = if (checked[index]) Color.Black else Color.Red
)
}
}
}
}
Michael Friend
07/30/2023, 6:11 PMColton Idle
08/02/2023, 3:24 PM