Create CardView in KMP KMM Compose Multiplatform

Today’s tutorial will teach us how to create CardView in KMP KMM Compose Multiplatform for both Android & iOS platforms. This step-by-step guide covers setting up elevation, setting round corner edges, adding background color, adding a click-onClick listener, and adding images and text on CardView.

Create CardView in KMP KMM Compose Multiplatform

Create CardView in KMP KMM Compose Multiplatform:

1. I am showing a local Image from the common resource folder for testing purposes. You can download the below image.

Demo Image for KMP tutorial

2. Start Android Studio and paste the image into

composeApp -> commonMain -> composeResource -> drawable folder.

KMP common resource folder for Image

3. Now you have to Rebuild the project To use the local image. Without rebuilding the project, the local image will not be synced into the project.

Rebuild KMP project

4. Creating a Card widget.

Code explanation:

  • Modifier.padding(): Adding padding to the CardView widget.
  • fillMaxWidth(): Setting up the Card view widget width fill parent.
  • clickable: Adding click listener on CardView.
  • elevation: Setting up elevation – drop shadow effect on CardView.
  • RoundedCornerShape(): Setting up Card edges rounded.
  • backgroundColor: Setting up background color to CardView. I am using Hex color code.

5. Now, we must first add a Row widget inside the Card View as Child, then add Image and multiple Text widgets.

Complete source code for App.kt file:

Screenshot in Android device:

Create CardView in KMP KMM Compose Multiplatform

Screenshot in iOS device:

iOS Card View

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *