Loading, Success & Error UI
Render every network outcome cleanly.
Every Request Has Three Outcomes
A network call is either still loading, finished with data, or failed. Great screens show something honest for all three.
Model State With a Sealed Class
A sealed class captures those outcomes as distinct types, so the compiler forces you to handle each case in the UI.
sealed class UiState {
object Loading : UiState()
data class Success(val users: List<User>) : UiState()
data class Error(val message: String) : UiState()
}All lessons in this course
- Define a Retrofit API Interface
- Parsing JSON with Moshi
- suspend Calls in the ViewModel
- Loading, Success & Error UI