0PricingLogin
Jetpack Compose Academy · Lesson

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

  1. Why ViewModel Survives Rotation
  2. viewModel() in a Composable
  3. Modeling a UiState Data Class
  4. collectAsStateWithLifecycle
← Back to Jetpack Compose Academy