38

I've created the simple card in jetpack compose, Here I set elevation but it shows a type mismatch.

Card(
            shape = RoundedCornerShape(20.dp),elevation = 10.dp
        ) {
            Box(modifier = Modifier.height(200.dp)) {
                Image(painter = painter, contentDescription = contentDescription,
                contentScale = ContentScale.Crop)
            }

    }

An image of an error appearing in an editor. The error reads, "Type mismatch. Required: CardElevation. Found: Dp."

Slate
  • 221
  • 5
  • 14
RaJ
  • 775
  • 2
  • 8
  • 21

1 Answers1

90

You are using M3 (androidx.compose.material3) Card and the elevation attribute requires a CardElevation object:

Something like:

Card(
    shape = RoundedCornerShape(20.dp),
    elevation = CardDefaults.cardElevation(
        defaultElevation = 10.dp
    )
)
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841