Yes. Use a mutablestate boolean, set it to true in
onClick
then call Dialog if boolean is true.
l
louiscad
08/20/2021, 10:05 AM
Yes, by changing a state, and have the dialog be shown based on the value of that state.
louiscad
08/20/2021, 10:05 AM
Dominic, you won this time, by a thin margin!
🥷🏼 1
😄 8
l
Lukas K-G
08/20/2021, 10:06 AM
Thanks for the help. Appreciate! 🙏
y
Yan Pujante
08/21/2021, 6:34 AM
At the end of the day your question is very valid/good question because it directly relates to the fundamental shift in thinking between traditional UI programming (callbacks, etc...) and state based (like compose/react, etc..). In this instance, clicking a menu item needs to change the state of the application by stating: this specific dialog window is opened. Until dismissed (Ok/Cancel/...), it stays open. When dismissed, the state changes again. This is why you need to represent this state as suggested by a mutable state boolean (or enum if you have multiple types of dialog windows that could be opened,...). Then in your code you simply do:
Thanks @Yan Pujante, I also realized that this boils down to the very fundamentals of writing the UI in compose. Quite a big part of my application needed a rewrite after that, but it feels way better now. 🙂