Search code examples
androidkotlinandroid-jetpack-composeandroid-jetpack-compose-material3

How to use material3 custom dialog in jetpack compose


I want to build Alert Dialog with options selection with rounded corners. I tried Material 3 library Alert Dialog code. I was looking this answer but getting weird errors. I have BOM version is compose_bom = "2022.11.00"

@Composable
fun DialogOptionsView() {
    AlertDialog(
        onDismissRequest = {}
    ) {
        Surface(
            modifier = Modifier
                .wrapContentWidth()
                .wrapContentHeight(),
            shape = MaterialTheme.shapes.large
        ) {

        }
    }
}

Error I am getting

Type mismatch.
Required:
DialogProperties
Found:
() → Unit

Error Image

enter image description here


Solution

  • The BOM package contains only stable versions of the different Compose libraries. In particular the BOM 2022.11.00 contains the androidx.compose.material3:material3:1.0.1

    To use the content parameter with AlertDialog you have to use at least the version 1.1.0-alpha04 of M3.

    In your build.gradle use:

    dependencies {
        // Import the Compose BOM
        implementation platform('androidx.compose:compose-bom:2023.01.00')
    
        // Override Material Design 3 library version with a pre-release version
        implementation 'androidx.compose.material3:material3:1.1.0-alpha05'
    
       //...
    }
    

    Also check the BOM to libraries mapping.