https://kotlinlang.org logo
Title
a

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 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

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
_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

ursus

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