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 ?
s
Semir Rahic
02/12/2022, 6:20 AM
You add an additional state „Loading“ to Success and Error.
This could also be the initial value of your StateFlow. And every time you set the StateFlow to „Loading“ (eg before you start your search) you show the loading UI in your activity
🙌 1
t
Tim Oltjenbruns
02/12/2022, 6:00 PM
Do you need any refresh capability here? If you follow the sealed class pattern here, make sure to have your Loading state contain the previous state (success/error) so the view can continue rendering the previous state while loading.