Sorry for cross posting here. Anyone has a clue wh...
# multiplatform
s
Sorry for cross posting here. Anyone has a clue why savedstatehandle does not work with koin? I have no more ideas.
c
Please also show us how are you initializing the HomeViewModel? I think you can just call get() to get reference of SavedStateHandle injected as per https://insert-koin.io/docs/4.1/reference/koin-android/viewmodel#savedstatehandle-injection-330
s
This is the code:
Copy code
MaterialTheme {
        NavHost(
            navController = navController,
            startDestination = if (isLoggedIn) {
                Home.name
            } else {
                Login.name
            },
            modifier = Modifier.fillMaxSize(),
        ) {
            composable(route = Login.name) {
                val vm: LoginViewmodel = koinViewModel()
                val state: LoginUiState by vm.uiStateFlow.collectAsStateWithLifecycle()
                LoginScreen(vm, state)
            }
            composable(route = Home.name) {
                val vm: HomeViewmodel = koinViewModel()
                val state by vm.uiState.collectAsStateWithLifecycle()
                HomeScreen(navController, state, vm::onAction)
            }
        }
    }
koinNavViewModel is deprecated and it sugests replacing with koinViewModel
c
I am using
koinViewModel()
and
SavedStateHandle
instance is being injected correctly. Did you follow the link I pasted?
s
Looks like the link is not working anymore
c
s
is there a small sample KMP project I can check, using koin, compose multiplatform and SavedStateHandle?
This is for Android right?
c
Yeah, but it works for compose multiplatform as well. I recently tried in my personal project which is closed source. I was able to retrieve the navigation argument via savedstatehandle after navigation.