Modeling a UiState Data Class
Represent the screen with one state object.
One Object for the Screen
Instead of juggling many separate fields, model the whole screen with a single UiState data class that describes exactly what to draw.
data class ProfileUiState(
val name: String = "",
val isLoading: Boolean = false
)Why One State Object
Grouping fields together prevents impossible combinations and makes the UI a pure function of one value: same state in, same screen out.
All lessons in this course
- Why ViewModel Survives Rotation
- viewModel() in a Composable
- Modeling a UiState Data Class
- collectAsStateWithLifecycle