Why recomposition doesn't happen when TextFieldValue changes

cy199025 注册会员
2023-01-25 18:38

So I am not sure how are you using this callback to get more items. Simplified it would be like:

val mutableNamesList = MutableStateFlow(listOf())
val namesList = mutableNamesList.asStateFlow()

fun NamesList() {
    val coroutineScope = rememberCoroutineScope()
    var text by remember { mutableStateOf("") }
    TextField(value = text, onValueChange = { newTextValue ->
        text = newTextValue
        coroutineScope.launch {
            mutableNamesList.value = ( mutableNamesList.value + newTextValue)
   val list =  namesList.collectAsState().value
    LazyColumn {
        items(list) { item ->
            Text(text = item)

Just, I used this import:

import androidx.compose.foundation.lazy.items
2023-01-25 18:38

Once I had the same question (you can see it and some other answers here). if shortly, flow is updated only when you emit the new object to it (with different hashcode than the last emitted item). and you are updating the same list and then trying to pass it to flow. if you will create the copy of the list and emit this copy, everything will work ok, as it is already another object