Hi, why i can't receive any notification when stat...
# compose
n
Hi, why i can't receive any notification when state changed like this:
Copy code
data class Question(var add: Boolean = true)
Copy code
val testState = MutableLiveData<List<Question>>()
testState.value = listOf(Question(false))
val state = testState.observeAsState()
RedButton(
    text = state.value?.get(0)?.add?.toString() ?: "?",
    btnColor = Color.Red,
    modifier = Modifier.clickable {
        testState.value = testState.value.apply {
            this?.get(0)?.add = true
        }
    })
l
I guess you should use “by” keyword 🙂
n
"by" just a delegator ,the reason not this
a
Standard properties don't magically become observable in compose. I would suggest you make your data class immutable (
data class Question(val add: Boolean = true)
) and use a
mutableStateListOf<Question>()
. Then you update the item like this:
list[0] = Question(add = false)
.
This post may help you understand.
🙌 2