Hello, I'm having an issue with coin and savedstat...
# koin
e
Hello, I'm having an issue with coin and savedstatehandle: Data is just null when trying to access it Koin module and version: 4.1.0-Beta5 TypeSafe Navigation:
Copy code
composable<Route.AddEditDreamScreen> { backStackEntry ->
                val args = backStackEntry.toRoute<Route.AddEditDreamScreen>()
                val image = args.backgroundID

                val addEditDreamViewModel = koinViewModel<AddEditDreamViewModel>()

                println("Dream ID: ${navController.currentBackStackEntry?.savedStateHandle?.get<String>("dreamID")}")
                AddEditDreamScreen(
                    dreamImage = image,
                    onMainEvent = { onMainEvent(it) },
                    onAddEditDreamEvent = { addEditDreamViewModel.onEvent(it) },
                    animateVisibilityScope = this,
                    onNavigateToDreamJournalScreen = {
                        navController.popBackStack()
                        navController.navigate(Route.DreamJournalScreen)
                    },
                    onImageClick = { imageID ->
                        navController.navigate(
                            Route.FullScreenImageScreen(imageID)
                        )
                    }
                )
            }
Koin:
Copy code
val viewModelModule = module {
    viewModelOf(::AddEditDreamViewModel)
}
ViewModel:
Copy code
class AddEditDreamViewModel(
    private val savedStateHandle: SavedStateHandle,
    private val dreamUseCases: DreamUseCases,
    private val authRepository: AuthRepository,
    private val dictionaryRepository: DictionaryRepository,
    private val vibratorUtil: VibratorUtil,
) : ViewModel() {

    private val _addEditDreamState = MutableStateFlow(
        AddEditDreamState(
            authRepository = authRepository
        )
    )
    val addEditDreamState: StateFlow<AddEditDreamState> = _addEditDreamState.asStateFlow()


    init {
        savedStateHandle.get<String>("dreamID")?.let { dreamId -> //value is Null (worked before transition to KMM)
        }
    }
This problem started after I transitioned my project from Android to KMM. Am I doing something wrong?
a
there is a known issue on that point, where the savedstate bundle from navigation (backstack entry) and those injected in VM are not the same. It's Android design on that. https://github.com/InsertKoinIO/koin/issues/2044
👍 1
e
The error ended up being some else. I was able to see it wasn't a problem with the SavedStateHandle after setting up logging.
👍 1