Kinar Sharma
07/06/2025, 10:39 AMviewModel: ScreenAViewModel = viewModel { ScreenAViewModel() }
I ran the Web app and it's failing at compilation with the following errors
e: user/Demo/composeApp/src/commonMain/kotlin/com/example/demo/screenA/ScreenA.kt:21:37 Unresolved reference 'compose'.
e: user/Demo/composeApp/src/commonMain/kotlin/com/example/demo/screenA/ScreenA.kt:32:33 Cannot infer type for this parameter. Specify it explicitly.
e: user/Demo/composeApp/src/commonMain/kotlin/com/example/demo/screenA/ScreenA.kt:32:33 Parameter 'viewModel' is uninitialized here.
e: user/Demo/composeApp/src/commonMain/kotlin/com/example/demo/screenA/ScreenA.kt:32:33 Unresolved reference. None of the following candidates is applicable because of a receiver type mismatch:
fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R
can please someone explain why is it failing?Kinar Sharma
07/07/2025, 6:46 AMzsmb
07/07/2025, 6:53 AMKinar Sharma
07/07/2025, 6:57 AMimport androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import cmp_di_poc.composeapp.generated.resources.Res
import cmp_di_poc.composeapp.generated.resources.compose_multiplatform
import com.egor.example.cmp_di_poc.screenB.ScreenBJourney
import org.jetbrains.compose.resources.painterResource
@Composable
fun ScreenA(
navController: NavController,
viewModel: ScreenAViewModel = viewModel { ScreenAViewModel() }
) {
var showContent by remember { mutableStateOf(false) }
Column(
modifier = Modifier
.safeContentPadding()
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Button(onClick = { navController.navigate(ScreenBJourney) }) {
Text("Go to ScreenB")
}
Button(onClick = { showContent = !showContent }) {
Text("Click me!")
}
AnimatedVisibility(showContent) {
//val greeting = remember { Greeting().greet() }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Image(painterResource(Res.drawable.compose_multiplatform), null)
//Text("Compose: $greeting")
}
}
}
}
Kinar Sharma
07/07/2025, 7:06 AMimport androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
class ScreenAViewModel : ViewModel() {
private val _imageStateFlow = MutableStateFlow(false)
val imageStateFlow = _imageStateFlow.asStateFlow()
fun showContent(isVisible: Boolean) {
println("isVisible: $isVisible")
_imageStateFlow.value = isVisible
}
}
zsmb
07/07/2025, 7:22 AMviewModel
function comes from, so
org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose
zsmb
07/07/2025, 7:23 AMViewModel
class in the first place. This just adds the Compose integrations like the viewModel {}
function.zsmb
07/07/2025, 7:24 AMKinar Sharma
07/07/2025, 7:34 AM