Building a cross-platform app
The main goal when using a cross-platform framework is to reuse code. However, there are situations when you want to do different things, depending on the platform. Kotlin Multiplatform and Compose Multiplatform help you achieve this with two new Kotlin keywords, expect and actual. Let’s see how they work.
The following code is part of compose-multiplatform-template. It’s inside shared/src/commonMain/kotlin/App.kt:
@Composable
fun App() {
MaterialTheme {
var greetingText by remember
{ mutableStateOf("Hello, World!") }
var showImage by remember { mutableStateOf(false) }
Column(
Modifier.fillMaxWidth(),
horizontalAlignment =
Alignment.CenterHorizontally) {
...