Challenge - 5 Problems
Card Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the visual output of this Card composable code?
Consider this Kotlin Compose code snippet for a Card. What will the user see on the screen?
Android Kotlin
Card( modifier = Modifier.size(100.dp), elevation = 8.dp ) { Text("Hello Card", modifier = Modifier.padding(16.dp)) }
Attempts:
2 left
💡 Hint
Remember that Card adds elevation by default and the Text has padding inside the card.
✗ Incorrect
The Card composable creates a container with elevation (shadow). The Text inside has padding, so the text is not touching the edges. This results in a visible card with shadow and padded text.
❓ lifecycle
intermediate2:00remaining
What happens when you update the state inside a Card composable?
If you have a Card composable displaying a counter and you update the counter state, what happens to the Card UI?
Android Kotlin
var count by remember { mutableStateOf(0) }
Card {
Text("Count: $count")
}
// On button click: count++Attempts:
2 left
💡 Hint
Compose automatically updates UI when state changes inside composables.
✗ Incorrect
Compose tracks state changes and recomposes only the affected composables. Updating the count triggers recomposition of the Card, so the new count is shown immediately.
📝 Syntax
advanced2:00remaining
Which option correctly sets a rounded corner shape on a Card?
You want to create a Card with rounded corners of 12.dp radius. Which code snippet does this correctly?
Attempts:
2 left
💡 Hint
Look for the correct parameter name and type for shape in Card composable.
✗ Incorrect
The Card composable uses the 'shape' parameter with a RoundedCornerShape object to set corner radius. Other options use incorrect parameter names or types.
advanced
2:00remaining
How to navigate to a new screen when a Card is clicked?
You want to navigate to a DetailScreen when the user taps on a Card. Which approach correctly handles this?
Android Kotlin
Card(modifier = Modifier.clickable { /* navigate */ }) {
Text("Go to Details")
}Attempts:
2 left
💡 Hint
Card itself does not have an onClick parameter; use Modifier.clickable instead.
✗ Incorrect
Card composable does not have an onClick parameter. To make it clickable, use Modifier.clickable and inside its lambda call navController.navigate("detail") to navigate.
🔧 Debug
expert2:00remaining
Why does this Card not show elevation shadow?
This Card composable code does not show any shadow even though elevation is set. What is the cause?
Android Kotlin
Card( modifier = Modifier.size(100.dp), elevation = 8.dp, backgroundColor = Color.Transparent ) { Text("No Shadow") }
Attempts:
2 left
💡 Hint
Think about how transparent backgrounds affect shadows in Compose.
✗ Incorrect
When backgroundColor is set to Transparent, the Card's shadow is not drawn because the surface is fully transparent. To see shadow, use a non-transparent background color.