# AlertDialog

> AlertDialog from Material 3 Compose (`androidx.compose.material3:material3`) for Jetpack Compose, with a code sample.

- Library: [Material 3 Compose](https://composables.com/material-components/material-3-compose.md)
- Category: [Dialogs](https://composables.com/material-components/dialogs.md)
- API reference and more examples: [AlertDialog](https://composables.com/jetpack-compose/androidx.compose.material3/material3/components/AlertDialog/api.md)

## Code

```kotlin
@Composable
fun AlertDialogSample() {
    val openDialog = remember { mutableStateOf(true) }

    Button(onClick = { openDialog.value = true }) { Text("Open dialog") }

    if (openDialog.value) {
        AlertDialog(
            onDismissRequest = {
                // Dismiss the dialog when the user clicks outside the dialog or on the back
                // button. If you want to disable that functionality, simply use an empty
                // onDismissRequest.
                openDialog.value = false
            },
            title = { Text(text = "Title") },
            text = { Text(text = "Turned on by default") },
            confirmButton = {
                TextButton(onClick = { openDialog.value = false }) { Text("Confirm") }
            },
            dismissButton = {
                TextButton(onClick = { openDialog.value = false }) { Text("Dismiss") }
            },
        )
    }
}
```
