InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.77k stars 695 forks source link

SavedStateHandle instance not the same as in NavBackStackEntry #1815

Open alex-kor opened 3 months ago

alex-kor commented 3 months ago

Describe the bug Trying to update SavedStateHandle which is accessible from NavBackStackEntry, and then read those values from a ViewModel which has a SavedStateHandle, and I see no values in there. Checked the instance ID and I see that ViewModel has different instance than a NavBackStackEntry. Question is how to get the same instance. I have a workaround which is working fine, but it would be nice to have it resolved and not jumping arround.

To Reproduce make a composable navGraph with 2 routes. When navigating from route 1 to 2 update savedStateHandle the way like so:

backStackEntry.savedStateHandle[PRODUCT_FAMILY_NAME_PARAM] = "test data"

then inside a ViewModel try to read it like so

checkNotNull(savedStateHandle[PRODUCT_FAMILY_NAME_PARAM])

Expected behavior I should get a "test data" string but get nothing

Koin module and version: koin-core:3.4.3

Snippet or Sample project to help reproduce Add a snippet or even a small sample project to hel reproduce your case.

timonmw commented 3 months ago

I have the same Problem. What is your workaround?