[Jetpack Compose] Alertダイアログを表示する

実装

@Composable
fun MyDialog() {
	var isShowDialog by remember { mutableStateOf(false) }

	Box(
		modifier = Modifier
			.fillMaxSize(),
		Alignment.Center
	) {
		Button(onClick = { isShowDialog = true} ) {
			Text(text = "Show Modal")
		}
	}
	if (isShowDialog) {
		AlertDialog(
			onDismissRequest = { isShowDialog = false },
			title = { Text("Important Message") },
			text = { Text(text = "This is a modal view example.") },
			confirmButton = {
				TextButton(onClick = { isShowDialog = false }) {
					Text(text = "OK")
				}
			},
			dismissButton = {
				TextButton(onClick = { isShowDialog = false }) {
					Text(text = "Cancel")
				}
			}
		)
	}
}