Hatice Sarp
06/27/2021, 8:04 PMHatice Sarp
06/27/2021, 8:05 PMvar 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
AlertDialog(
onDismissRequest = {
onDismiss.invoke()
} ...
)
Zach Klippenstein (he/him) [MOD]
06/27/2021, 8:19 PMdeleteResult.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
.