0Pricing
Jetpack Compose Academy · Ders

UiState Veri Sınıfını Modelleme

Ekranı tek bir durum nesnesiyle temsil edin.

UiState Veri Sınıfını Modelleme, CoddyKit'te ücretsiz bir Jetpack Compose Academy dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Jetpack Compose Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

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.

Make It Immutable

Use val properties so a UiState can never be mutated in place. You always produce a new state, which keeps Compose updates predictable.

Updating With copy

Data classes give you copy() for free, so you can build the next state by changing only the fields that differ.

val next = state.copy(isLoading = false)

Modeling Loading

Capture progress with a flag like isLoading so the UI can show a spinner while work runs, all from the same state object.

Modeling Errors

Add a nullable errorMessage field. When it is non-null, the screen shows the error; when null, everything is fine. ⚠️

data class UiState(
    val items: List<Item> = emptyList(),
    val errorMessage: String? = null
)

Sealed Classes for Phases

For mutually exclusive phases, a sealed hierarchy is cleaner: Loading, Success, and Error become distinct types you handle exhaustively.

sealed interface UiState {
    object Loading : UiState
    data class Success(val data: List<Item>) : UiState
}

Sensible Defaults

Give every property a default value so the initial state is one easy expression and new screens start in a clean, known condition.

private val _state = MutableStateFlow(ProfileUiState())

Exposing It Read-Only

Hold a mutable state inside the ViewModel but expose it as a read-only type, so only the ViewModel may change the screen’s state.

val state: StateFlow<ProfileUiState> = _state.asStateFlow()

Rendering From It

Your Composable reads one UiState and branches on its fields. The render logic stays tiny because the state already says what to show.

Single Source of Truth

A UiState class becomes the single source of truth for the screen, so your UI and logic can never quietly drift out of sync. ✨

Quick Check

Test your modeling instincts for screen state.

Recap

Model the screen with one immutable UiState data class, update it with copy(), expose it read-only, and let the UI render purely from that single source.

Sıkça Sorulan Sorular

“UiState Veri Sınıfını Modelleme” dersi ücretsiz mi?

Evet — “UiState Veri Sınıfını Modelleme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Jetpack Compose Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.

“UiState Veri Sınıfını Modelleme” dersinde ne öğreneceğim?

Ekranı tek bir durum nesnesiyle temsil edin. Jetpack Compose Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Jetpack Compose Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Jetpack Compose Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“UiState Veri Sınıfını Modelleme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Jetpack Compose Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Jetpack Compose Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. ViewModel Döndürmeden Neden Sağ Kalır
  2. Composable İçinde viewModel()
  3. UiState Veri Sınıfını Modelleme
  4. collectAsStateWithLifecycle
← Jetpack Compose Academy Sayfasına Dön