I have a strange issue. ViewModel get data from db...
# compose
g
I have a strange issue. ViewModel get data from db with a viewModelScope... after update a list in my uiStage model.. is a MutableStateFlow... when i put a brakpoint i see change while without brakpoint ui doesn/t change.
Copy code
viewModelScope.launch {
    var confirmedList = getItemsConfirmedByScodeUseCase.invoke()

    var groups = confirmedList.groupBy { it }
    var modules = uiState.value.modules
    modules.forEach {
        it.badge = ""
    }
    groups.forEach { op, list ->
        modules.forEach {
            if (it.operationId == op) {
                it.badge = list.size.toString()
            }
        }
    }
    uiState.value = uiState.value.copy(
        modules = modules
    )
}
modules is a list inside my
Copy code
val uiState = MutableStateFlow<DashboardState>(DashboardState(false))
i
It looks like you are just editing the list items in place, rather than creating a new list instance with your updated data. Your copy() isn't actually doing anything useful here since
uiState.value.modules
is being changed out from underneath it, meaning your previous emission and new emission are
.equals()
to one another, which is why you don't get any state change in Compose
Generally, you'll want to avoid mutable items and mutable lists entirely when using StateFlow
g
thanks
i moved calculate badges before create Module list so.. i avoid use "`uiState.value.modules`"