I have a case where I am assigning the stateflow i...
# flow
v
I have a case where I am assigning the stateflow in viewmodel to the usecase stateflow like below class TestModel: ViewModel() { private var discoverTag = MutableStateFlow(false)
Copy code
fun initiate(){
viewModelScope.launch {
Copy code
discoverTag = usecase.tag
}
}
Where
tag
is stateflow in usecase which emits the value The problem here is that the discover tag is only collected for the first time but not when emitted from usecase
j
I’m guessing this is because you have two different flows that can be referenced here. You are initializing discoverTag to a MutableStateFlow instance and then in initiate you are reassigning it to reference
usecase.tag
. If you are calling
discoverTag.collect
before
initiate
is called then you are collecting on that first MutableStateFlow and not on
usecase.tag
.