Hi everyone! While deleting the account, I open t...
# compose
h
Hi everyone! While deleting the account, I open three different alert dialogs in a row. I keep mutableState to dismiss alert dialogs. After the second alert dialog, I throw the delete request. According to the result of this request, I show the third alert dialog. The third dialog does not dismiss. What do you think could be the reason?
Copy code
var dialogState by remember { mutableStateOf(DialogState(false, DialogType.DELETESTEP1)) }
val deleteResult = viewModel.deleteAcResult.collectAsState()
if (deleteResult.value?.success == true) {
    dialogState = DialogState(true, DialogType.DELETESTEP3)
}

if (dialogState.showDialog) {
    when (dialogState.dialogType) {
        DialogType.DELETESTEP1 -> {
            DeleteDialog(
                title = "title",
                text = "text",
                positiveText = "positiveText",
                negativeText = "negativeText",
                onDismiss = {
                    dialogState = dialogState.copy(showDialog = false, dialogType = DialogType.NOTHING)
                },
                onConfirm = {
                    dialogState = dialogState.copy(showDialog = true, dialogType = DialogType.DELETESTEP2)

                }
            )

        }
        DialogType.DELETESTEP2 -> {
            DeleteDialog(
                title = "title",
                text = "text",
                positiveText = "positiveText",
                negativeText = "negativeText",
                onDismiss = {
                    dialogState = dialogState.copy(showDialog = false, dialogType = DialogType.NOTHING)
                },
                onConfirm = {
                    onDeleteAccount()
                })
        }
        DialogType.DELETESTEP3 -> {
            DeleteDialog(
                title = "title",
                text = "text",
                positiveText = "positiveText",
                negativeText = "negativeText",
                onDismiss = {
                    dialogState = dialogState.copy(showDialog = false, dialogType = DialogType.NOTHING)
                },
                onConfirm = {  onOkClick() })
        }
    }
Alert Dialog in DeleteDialog composable
Copy code
AlertDialog(
    onDismissRequest = {
        onDismiss.invoke()
    } ...
)
z
Does
deleteResult.value.success
stay true after
onOkClick()
? If so, then whenever your composable recomposes your will set the state back to show dialog 3. One issue with this code is that there are two sources of truth for the third dialog. Instead of reading one state and conditionally setting another state, I would recommend just reading the delete result status in your
when
.
👍 2