diff --git a/samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt b/samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt index 785ba06c7..d923f6ce1 100644 --- a/samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt +++ b/samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt @@ -33,10 +33,8 @@ val client by lazy { @Composable fun App() { - var serviceOrNull: UserService? by remember { mutableStateOf(null) } - - LaunchedEffect(Unit) { - serviceOrNull = client.rpc { + val rpcClient = remember { + client.rpc { url { host = DEV_SERVER_HOST port = 8080 @@ -48,53 +46,51 @@ fun App() { json() } } - }.withService() + } } - val service = serviceOrNull // for smart casting + val service: UserService = remember { rpcClient.withService() } - if (service != null) { - var greeting by remember { mutableStateOf(null) } - val news = remember { mutableStateListOf() } + var greeting by remember { mutableStateOf(null) } + val news = remember { mutableStateListOf() } - LaunchedEffect(service) { - greeting = service.hello( - "User from ${getPlatform().name} platform", - UserData("Berlin", "Smith") - ) - } + LaunchedEffect(service) { + greeting = service.hello( + "User from ${getPlatform().name} platform", + UserData("Berlin", "Smith") + ) + } - LaunchedEffect(service) { - service.subscribeToNews().collect { article -> - news.add(article) - } + LaunchedEffect(service) { + service.subscribeToNews().collect { article -> + news.add(article) } + } - MaterialTheme { - var showIcon by remember { mutableStateOf(false) } + MaterialTheme { + var showIcon by remember { mutableStateOf(false) } - Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { - greeting?.let { - Text(it) - } ?: run { - Text("Establishing server connection...") - } + Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { + greeting?.let { + Text(it) + } ?: run { + Text("Establishing server connection...") + } - news.forEach { - Text("Article: $it") - } + news.forEach { + Text("Article: $it") + } - Button(onClick = { showIcon = !showIcon }) { - Text("Click me!") - } + Button(onClick = { showIcon = !showIcon }) { + Text("Click me!") + } - AnimatedVisibility(showIcon) { - Column( - Modifier.fillMaxWidth(), - horizontalAlignment = Alignment.CenterHorizontally - ) { - Image(painterResource(Res.drawable.compose_multiplatform), null) - } + AnimatedVisibility(showIcon) { + Column( + Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Image(painterResource(Res.drawable.compose_multiplatform), null) } } } diff --git a/samples/ktor-all-platforms-app/gradle/libs.versions.toml b/samples/ktor-all-platforms-app/gradle/libs.versions.toml index 820c4b13c..10bbab110 100644 --- a/samples/ktor-all-platforms-app/gradle/libs.versions.toml +++ b/samples/ktor-all-platforms-app/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] kotlin = "2.2.0" -agp = "8.11.0-alpha07" +agp = "8.11.0" android-compileSdk = "36" android-minSdk = "24" android-targetSdk = "36"