Home > OS >  Invocations can only happen from the context of a @Composable function
Invocations can only happen from the context of a @Composable function

Time:07-27

Trying to invoke this in a DropDownMenuItem onClick event.

@Composable
fun ShowAboutDialog() {
    var aboutVisible by remember { mutableStateOf(false) }
    Dialog(visible = !aboutVisible, onDismissRequest = { aboutVisible = false },
        modifier = null,
        properties = null,
        icon = {
            Icon(
                imageVector = Icons.Rounded.ThumbUp,
                contentDescription = null,
            )
        },
        title = {
            Text(text = "About this app")
        },
        text = {},
        confirmButton = {},
        dismissButton = {}
    )
}




  DropdownMenuItem(text = { Text("About", fontSize = 16.sp) },
                                            onClick = {
                                            showMenu = false
                                              ShowAboutDialog()
                                            })

CodePudding user response:

The composable functions can be called only from another composable function. Here the ShowAboutDialog() function is a compose function and if you need to call that, you need to call it from another composable function with @Composable annotation added like another composable screen or function.

  • Related