Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This material API is experimental and is likely to change or to be removed in the future. error in android when using new material3 card

How to set elevation for material3 card? I am using new material3 card and getting error

This material API is experimental and is likely to change or to be removed in the future.

Here is code ->

    @ExperimentalMaterial3Api
    @Composable
    fun ProfileCard(
        modifier: Modifier = Modifier
    ) {
        Card(
            modifier = modifier
                .fillMaxWidth()
                .wrapContentHeight()
                .padding(all = 16.dp),
            shape = RoundedCornerShape(size = 16.dp),
            containerColor = MaterialTheme.colorScheme.surface,
            border = BorderStroke(width = 1.dp, color = MaterialTheme.colorScheme.inverseOnSurface),
            elevation = CardDefaults.outlinedCardElevation()
        ) {
    ...
        }
    }

I am not able to run app due to error caused by elevation how to set elevation?

Edit : Solved the issue by adding

elevation = CardDefaults.outlinedCardElevation(defaultElevation = 1.dp)

Why do we have to add border for CardDefaults.outlinedCardElevation why does't it show by default?

like image 516
Vidyesh Churi Avatar asked Nov 27 '25 03:11

Vidyesh Churi


1 Answers

If you find the same message in the future for another reason, one option could be to add in your build.gradle file, the following:

kotlinOptions {
    allWarningsAsErrors = false
    freeCompilerArgs += [
        '-opt-in=androidx.compose.material3.ExperimentalMaterial3Api'
    ]
}

In this way, after Sync Project with Gradle Files you will not see the warnings in your compose code.

like image 184
Nelson Avatar answered Nov 28 '25 15:11

Nelson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!