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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With