Hi everyone, I try to implement StateFlow in viewm...
# coroutines
a
Hi everyone, I try to implement StateFlow in viewmodel, but i confused how to add Loading state, i try to follow official documentation https://developer.android.com/kotlin/flow/stateflow-and-sharedflow, but i think it's just show state success and error, my question is how to add loading state using StateFlow in viewmodel ?
n
It seems like what you want is to add a new LatestNewsUiState type (i.e. LatestNewsUiState.Loading), and set that to be the initial state (line where you declare
_uiState
). This will make it such that the screen appears initially in a loading state, then reverts to a success or error state as soon as data is ready.
🙌 1
u
onStart { emit(Loading) }
🙌 1