Skip to content

Instantly share code, notes, and snippets.

@Debdutta-Panda
Created June 23, 2022 15:37
Show Gist options
  • Save Debdutta-Panda/299e06c9ac51e5087cfa3493b8cf19d8 to your computer and use it in GitHub Desktop.
Save Debdutta-Panda/299e06c9ac51e5087cfa3493b8cf19d8 to your computer and use it in GitHub Desktop.
Dialog in jetpack compose
if(vm.isDialogOpen.value){
Dialog(
onDismissRequest = {
vm.dismissDialog()
},
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = true
)
) {
Card(
modifier = Modifier
.fillMaxWidth()
){
Column(
modifier = Modifier
.fillMaxWidth()
.padding(12.dp)
){
Text("Heading")
Divider()
Text("Message?")
Row(
modifier = Modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.End
){
TextButton(onClick = {
vm.onPositive()
}) {
Text("Positive")
}
Spacer(modifier = Modifier.width(12.dp))
TextButton(onClick = {
vm.onNegative()
}) {
Text("Negative")
}
}
}
}
}
}
val isDialogOpen = mutableStateOf(false)
fun showDialog() {
isDialogOpen.value = true
}
fun dismissDialog() {
isDialogOpen.value = false
}
fun onPositive() {
isDialogOpen.value = false
//do the other stuffs
}
fun onNegative() {
isDialogOpen.value = false
//do the other stuffs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment