How to display multiple dialog boxes in sequence w...
# compose
c
How to display multiple dialog boxes in sequence with the most elegant code? dialog1 -> dialog2 -> dialog3 (The messy code in the thread 😅 and maybe this is the flaw of declarative...
Terrible code:
Copy code
var dialogThird by remember { mutableStateOf(false) }
  if (dialogThird) {
    Dialog(onDismissRequest = {}) {
      Text(text = "Done")
    }
  }

  var dialogSecond by remember { mutableStateOf(false) }
  if (dialogSecond) {
    Dialog(onDismissRequest = {}) {
      Button(onClick = {
        dialogSecond = false
        dialogThird = true
      }) { Text(text = "Next") }
    }
  }

  var dialogFirst by remember { mutableStateOf(false) }
  if (dialogFirst) {
    Dialog(onDismissRequest = {}) {
      Button(onClick = {
        dialogFirst = false
        dialogSecond = true
      }) { Text(text = "Next") }
    }
  }
p
Maybe it would make sense to use an enum instead of boolean flags? Something with values like NONE, FIRST, SECOND, THIRD and clicking a button then just updates to the right state? This at least makes sure you don't accidentally display more than one dialog at the same time. But in general a dialog flow might not be the best UX
c
@patrick In fact, it starts as a menu dialog with an item to save an image. Clicking on it verifies that the image has been saved and, if so, displays an input dialog to allow the user to change the new name 🙂
In addition, there are other menu items that behave similarly, so the code can get pretty messy...
f
Probably not the answer you are looking for but I don't think Dialogs are suppopsed to be used this way. You probably want to use Bottom sheet or just show the info on different screen. Chaining dialogs seems really awkward from the UX standpoint to me.
☝️ 1
c
Or you can use a single dialog, with the layout swapping between them. So the entire dialog could be like a single wizard if you'd like.
d
Yes have the dialog update it's content in place is the correct solution if you have to use a dialog.
Also if you update it in place you could chain the state transitions together with some nice animations.
c
Sounds great, I will consider doing something that must be done in the form of updated content! thank you everyone 😁