Simple Dialog
A dialog pop-up window is a child of the main window. Dialogs are modal, meaning that they sit in front of the main window and must be closed before the user can interact with the main window again.
Dialogs can be easily shown / hidden through the use of a boolean state variable created via mutableStateOf(...). See the State page for more information on these.
Dialogs are laid out and can contain the same elements as a normal window.
fun main() = singleWindowApplication(
title = "Window with Dialog",
) {
App()
}
var isDialogOpen by mutableStateOf(false)
@Composable
fun App() {
Column() {
Text("This is the main window")
Button(
onClick = { isDialogOpen = true }
) {
Text(text = "See Extra Info")
}
}
if (isDialogOpen) {
Dialog()
}
}
@Composable
fun Dialog() = DialogWindow(
title = "Extra Info",
state = DialogState(width = 300.dp, height = 200.dp),
onCloseRequest = { isDialogOpen = false }
) {
Column() {
Text("Here is some additional information")
Button(
onClick = { isDialogOpen = false }
) {
Text(text = "Close")
}
}
}