https://kotlinlang.org logo
#flow
Title
# flow
v

Vikas Singh

06/27/2022, 5:59 AM
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

Joseph Hawkes-Cates

07/21/2022, 4:34 PM
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
.