Ahmad Dudayef

02/12/2022, 1:46 AM
Hi everyone, I try to implement StateFlow in viewmodel, but i confused how to add Loading state, i try to follow official documentation, but i think it's just show state success and error, my question is how to add loading state using StateFlow in viewmodel ?

Nathaniel Rowe

02/12/2022, 4:35 AM
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
). 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


02/12/2022, 7:25 PM
onStart { emit(Loading) }
🙌 1