Floating Action Button FAB in KMP Compose Multiplatform

In today’s tutorial, we will learn about the Floating action button FAB in KMP Compose Multiplatform for both Android & iOS platforms.

Floating Action Button FAB in KMP Compose Multiplatform

Integrate Floating Action Button FAB in KMP Compose Multiplatform:

Floating action buttons are primarily used to provide quick-click actions to app users. They are displayed at the Bottom right side of the Screen in a round shape. You can set the Image or Icon in the FAB as required. I am setting up Material vector icons using the Floating action button. There is no need to add any extra dependency in the Kotlin project.

Start coding for the app:

1. Creating a Box widget first. Because our floating action button will be on our entire screen.

2. Creating the FloatingActionButton widget in the Box widget as a Child.

Code explanation:

  • onClick: Pass your method here, which you want to call on the floating action button click event.
  • Modifier.padding(): Set padding from the bottom and end side of the screen to make floating action X and Y position on the screen.
  • backgroundColor: To set the background color of the button. I am using the HEX color code. You can also set the ARGB or RGBA color code.
  • Icon: Setting up material vector icon.
  • tint: Set the color of the vector icon.

3. Using the composable method, I am making the Floating action button as a custom reusable widget. So you can use it multiple times in your code.

Complete source code for App.kt file:

Output in Android device:

FAB Android KMP

Output in iOS device:

FAB iOS in KMP

Click output:

click listener on Floating action button in KMP compose multiplatform

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 *