Hi
I have one small doubt about flows:
StateFlow
to be specific
I have
MutableStateFlow<UiState>
and corresponding
StateFlow<UiState>
defined in my viewmodel
class MainViewModel:ViewModel() {
private val mutableUiState = MutableStateFlow(UiState())
val uiState = mutableUiState.asStateFlow()
// ...
}
And my UiState is roughly defined like this
data class UiState(
val propertyA: Int = 0,
val propertyB: Boolean = false
) {
private var mutableProperty: Int = 0
val derivedProperty: Boolean
get() = mutableProperty % 2 == 0
fun someMethod(newProperty: Int) {
mutableProperty = newProperty
// some extra logic goes here
}
}
Now the doubt is that in my viewmodel I’m calling
mutableUiState.someMethod(someInteger)
but I think
uiState
is not getting updated because I have used
uiState.derivedProperty
at some place in UI in compose and the UI is not updating.
Someone care to help what I’m doing wrong? Thanks