I am new in Jetpack Compose. I just implemented an AlertDialog
in Jetpack Compose. I'am not clear about Dialog show and dismiss process. Here is sample code:
@Composable
fun CreateAlertDialog() {
Column {
val openDialog = remember { mutableStateOf(false) }
Button(
onClick = {
openDialog.value = true
},
modifier = Modifier
.padding(16.dp)
.fillMaxWidth()
) {
Text(text = "Open Dialog")
}
if (openDialog.value){
AlertDialog(
onDismissRequest = {
openDialog.value = false
},
title = {
Text(text = "Dialog Title")
},
text = {
Text(text = "Text content")
},
confirmButton = {
Button(
onClick = {
openDialog.value = false
}
) {
Text(text = "Ok")
}
},
dismissButton = {
Button(
onClick = {
openDialog.value = false
}
) {
Text(text = "Cancel")
}
},
modifier = Modifier.padding(start = 32.dp, end = 32.dp)
)
}
}
}
This works fine, but i am not clear how dialog is dismissed here. Dialog is showing based on MutableState
It shows dialog when openDialog.value
this is true.
What happen after a Button
click ? When a Button
is clicked openDialog.value
becomes false
and dialog
is dismissed.
Where is dialog dismiss code executed?
How this state is handled ?
Can any one can explain this would be helpful to me.Thanks in advance.