Dialogs, Bottom Sheets and Snackbars
AlertDialog
kotlin
@Composable
fun DeleteDemo() {
var showDialog by remember { mutableStateOf(false) }
Button(onClick = { showDialog = true }) { Text("Delete account") }
if (showDialog) {
AlertDialog(
onDismissRequest = { showDialog = false },
title = { Text("Delete account?") },
text = { Text("This cannot be undone.") },
confirmButton = {
TextButton(onClick = { showDialog = false; /* delete */ }) { Text("Delete") }
},
dismissButton = {
TextButton(onClick = { showDialog = false }) { Text("Cancel") }
}
)
}
}
Compose pattern: There is no
dialog.show(). A dialog is simply a composable that appears when showDialog is true. Change the state and the dialog shows or hides.
Bottom Sheet
kotlin
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SheetDemo() {
var show by remember { mutableStateOf(false) }
val sheetState = rememberModalBottomSheetState()
val scope = rememberCoroutineScope()
Button(onClick = { show = true }) { Text("Options") }
if (show) {
ModalBottomSheet(onDismissRequest = { show = false }, sheetState = sheetState) {
Column(Modifier.padding(16.dp).navigationBarsPadding()) {
ListItem(headlineContent = { Text("Share") }, leadingContent = { Icon(Icons.Default.Share, null) },
modifier = Modifier.clickable {
scope.launch { sheetState.hide() }.invokeOnCompletion { show = false }
})
ListItem(headlineContent = { Text("Delete") }, leadingContent = { Icon(Icons.Default.Delete, null) })
}
}
}
}
Snackbar with Action
kotlin
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(snackbarHost = { SnackbarHost(snackbarHostState) }) { padding ->
Button(Modifier.padding(padding), onClick = {
scope.launch {
val result = snackbarHostState.showSnackbar(
message = "Item deleted",
actionLabel = "Undo",
duration = SnackbarDuration.Short
)
if (result == SnackbarResult.ActionPerformed) { /* restore the item */ }
}
}) { Text("Delete") }
}
Toast: The Old Quick Message
kotlin
val context = LocalContext.current
Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show()
Prefer Snackbar because it follows Material design and can have an Undo action.
Progress Indicators
kotlin
CircularProgressIndicator()
LinearProgressIndicator(progress = { 0.6f }, modifier = Modifier.fillMaxWidth())
| Component | Use for |
|---|---|
| AlertDialog | Important yes or no questions |
| Snackbar | Short messages and Undo |
| Bottom sheet | Extra options or a small task |
| Toast | Very simple system messages |
Conclusion
Dialogs and sheets are composables controlled by state. Use Snackbar for feedback, AlertDialog for important confirmations.
Quick Summary: Show AlertDialog, ModalBottomSheet and Snackbar by changing state, and handle results with callbacks.

