0Pricing
Jetpack Compose Academy · Ders

Snackbars ve SnackbarHostState

Geçici iletileri Material yaklaşımıyla gösterin.

Snackbars ve SnackbarHostState, CoddyKit'te ücretsiz bir Jetpack Compose Academy dersidir. Bu, 4 dersinin 4. 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.

What Is a Snackbar?

A Snackbar is a brief message that slides up at the bottom, like Message sent, then fades on its own. It informs without blocking the screen. 💬

Snackbar vs Dialog

A dialog demands a response; a Snackbar does not. Reach for it for quick confirmations, not for choices the user must make.

Meet SnackbarHostState

Showing a snackbar is driven by SnackbarHostState. This object holds the queue and gives you the function that triggers a message.

val hostState = remember { SnackbarHostState() }

Remember It

Wrap the state in remember so the same SnackbarHostState survives recomposition. A fresh one each frame would lose any pending message.

The snackbarHost Slot

Tell Scaffold where snackbars appear by filling its snackbarHost slot with a SnackbarHost bound to your state.

snackbarHost = { SnackbarHost(hostState) }

showSnackbar Is Suspend

The showSnackbar function suspends, because it waits while the message is visible. So you must call it from a coroutine, not directly in a click.

Launch From a Scope

Grab a rememberCoroutineScope and launch showSnackbar inside it. That bridges a normal onClick to the suspend call safely.

scope.launch {
    hostState.showSnackbar("Saved")
}

Add an Action

Pass an actionLabel to add a button, such as Undo. The call returns a result telling you whether the user tapped that action.

val result = hostState.showSnackbar(
    "Deleted", actionLabel = "Undo"
)

React to the Result

Check the returned SnackbarResult. If it equals ActionPerformed, run your undo logic; otherwise the snackbar simply dismissed.

if (result == SnackbarResult.ActionPerformed) {
    restoreItem()
}

Control the Duration

Set how long it lingers with SnackbarDuration: Short, Long, or Indefinite. Use Indefinite only when the message truly needs the user to act.

One Host, Many Messages

A single SnackbarHostState queues messages, showing them one at a time. So share one host per Scaffold rather than creating several.

Quick Check

Why must you launch showSnackbar inside a coroutine scope?

Recap

Remember a SnackbarHostState, wire it into Scaffold's snackbarHost, then launch showSnackbar from a scope. You can finish a polished app shell now. 🎉

Sıkça Sorulan Sorular

“Snackbars ve SnackbarHostState” dersi ücretsiz mi?

Evet — “Snackbars ve SnackbarHostState” 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.

“Snackbars ve SnackbarHostState” dersinde ne öğreneceğim?

Geçici iletileri Material yaklaşımıyla gösterin. 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 4. dersidir.

“Snackbars ve SnackbarHostState” 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. Scaffold: Ekran İskeleti
  2. TopAppBar ve Eylem Simgeleri
  3. Alt Çubuklar ve Kayan Eylem Düğmeleri
  4. Snackbars ve SnackbarHostState
← Jetpack Compose Academy Sayfasına Dön