I want to show an AlertDialog (material alert dial...
# compose
c
I want to show an AlertDialog (material alert dialog) but have it display my custom composable inside of it. The reasons why I want an alertDialog is because I want the size of an AlertDialog and I want it's container as well (i.e. an alertDialog seems to be on a rounded corner material card) Should I start with
Dialog
and try to morph it into alertDialog design, or is there a way to pass a composable into an AlertDialog that I'm missing?
l
Honestly it’s probably easier just to start with a
Dialog
- the implementation is trivial. It’s really just a
Dialog
with a
Surface
with a shape with rounded corners 🙂
c
@Louis Pullen-Freilich [G] thanks. I was leaning that way, but didn't know if I should just try to make the root element in my dialog a Card or something. Also the Dialog sample code here sets a hardcoded size on the Dialog which I thought was weird.
Copy code
val dialogWidth = 200.dp
    val dialogHeight = 50.dp
as I'm used to AlertDialogs in view-land basically always setting it's own size as it promotes consistency throughout the platform.
l
Yeah, well it’s just a sample of how to use a
Dialog
- you don’t have to set the size 🙂 It should just default to the framework’s default size for consistency. And yeah, you can just make the root a
Surface
, take a look at: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mmonMain/kotlin/androidx/compose/material/AlertDialog.kt;l=44 This is just placed inside a
Dialog
c
Thanks @Louis Pullen-Freilich [G] coming from the view world it's like... Wait. It can't be this easy can it? Lol