I have a usecase that i combine two flows and convert it to stateFlow by using statIn. When user clicks on the list, i want to update current ui state and pass it to my stateflow. Since it's not MutableStateFlow, i am not able to update it. The reason i dont use MutableStateFlow is i want to get benifit of using "WhileSubscribed".
The sample code is like below :
val state = getList().catch { // This flow emits every 5 seconds.
.....
}.combine(getSecondList().catch {
.....
}) { firstList, secondList ->
.....
.....
UiState.Success(firstList, secondList)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(FLOW_TIMEOUT), UiState.Loading)
fun updateList { // User clicks on list.
.....
.....
val state = (state.value as? UiState.Success)
val newState = state?.copy(updatedFirstList, updatedSecondList)
// Want to update state value here.
}
Is there any other way to achive what i want to do? Appreciate any help.