Reputation: 113
I want to show alert dialog when pressing back button. But I'm facing a problem.
This is my code:
BackHanlder{
AlertDialogComponent()
}
And I got this error:
@composable invocations can only happen from the context of an @composable function
Any help?
Upvotes: 1
Views: 1142
Reputation: 1473
To show alert dialog you have to keep the boolean value as state, and change it in back handler
var showAlertDialog by remember { mutableStateOf(false)}
BackHandler {
showAlertDialog = true
}
if(showAlertDialog){
AlertDialog(//)
}
Upvotes: 5