Skip to content

Instantly share code, notes, and snippets.

@tkuenneth
Created December 18, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkuenneth/456853d36ae31ff9f2cf9ead1cd87e70 to your computer and use it in GitHub Desktop.
Save tkuenneth/456853d36ae31ff9f2cf9ead1cd87e70 to your computer and use it in GitHub Desktop.
A Compose for Desktop example showing an AlertDialog
package com.thomaskuenneth
import androidx.compose.desktop.AppManager
import androidx.compose.desktop.Window
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.window.Menu
import androidx.compose.ui.window.MenuBar
import androidx.compose.ui.window.MenuItem
fun main() {
AppManager.setMenu(MenuBar(
Menu("File", MenuItem("Quit", onClick = {
AppManager.exit()
}))
))
Window(title = "AlertDialogDemo") {
val show = remember { mutableStateOf(false) }
Button(onClick = {
show.value = true
}) {
Text("Show AlertDialog")
}
if (show.value) {
AlertDialog(onDismissRequest = {},
title = {
Text("A title")
},
text = {
Text("A text")
},
confirmButton = {
Button(onClick = {}) {
Text("A button")
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment