Skip to content

Instantly share code, notes, and snippets.

@Sprajapati123
Created May 7, 2025 08:50
Show Gist options
  • Select an option

  • Save Sprajapati123/63d5586a00f837cbf974ab822a456707 to your computer and use it in GitHub Desktop.

Select an option

Save Sprajapati123/63d5586a00f837cbf974ab822a456707 to your computer and use it in GitHub Desktop.
package com.example.c36b
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@Composable
fun AlertDialogBody() {
var showDialog by remember { mutableStateOf(false) }
Column {
// Trigger to show the dialog
Button(onClick = { showDialog = true }) {
Text("Show AlertDialog")
}
if (showDialog) {
AlertDialog(
onDismissRequest = {
showDialog = false
}, // dismiss when clicked outside
confirmButton = {
Button(onClick = {
// Confirm action
showDialog = false
}) {
Text("OK")
}
},
dismissButton = {
Button(onClick = {
// Cancel action
showDialog = false
}) {
Text("Cancel")
}
},
title = { Text(text = "Alert Title") },
text = { Text("This is an alert dialog message.") }
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment