Jetpack Compose Show Confirm Dialog

@Composablefun test() {    var showDeleteConfirm by remember { mutableStateOf(false) }    Button(onClick = { showDeleteConfirm = true }) {        Text("Delete")    }    if (showDeleteConfirm) {        ConfirmDialog(            content = "Confirm Delete?",            onDismiss = { showDeleteConfirm = false },            onConfirm = {                showDeleteConfirm = false                onDelete() // perform actual operation            }        )    }}
@Composablefun ConfirmDialog(title: String? = null, content: String, onDismiss: () -> Unit, onConfirm: () -> Unit) {    AlertDialog(        modifier = Modifier.fillMaxWidth(),        onDismissRequest = {            onDismiss()        },        /*        // https://stackoverflow.com/questions/69452854/increase-space-between-title-and-text-of-alertdialog-in-compose        title = {           if (!title.isNullOrEmpty()) {               Text(title)           }        },         */        text = {            Column (                modifier = Modifier                    .fillMaxWidth()                    .padding(8.dp),                // horizontalAlignment = Alignment.CenterHorizontally            ) {                // CircularProgressIndicator()                // Text("Hello")                if (!title.isNullOrEmpty()) {                    Text(title,                        modifier = Modifier.padding(vertical = 8.dp),                        style = MaterialTheme.typography.subtitle1)                }                Text(content)                // Timber.d("message=${progressState.message}")            }        },        // buttons = { }        dismissButton = {            Button(onClick = { onDismiss() }) {                Text("No")            }        },        confirmButton = {            Button(onClick = { onConfirm() }) {                Text("Yes")            }        }    )}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.