Closed gmk57 closed 3 years ago
Just ran into this problem as well. I think the problem is in ViewModelResolver.kt
:
private fun <T : ViewModel> Scope.pickFactory(
viewModelParameters: ViewModelParameter<T>,
): ViewModelProvider.Factory {
return when {
viewModelParameters.registryOwner != null && viewModelParameters.initialState != null -> StateViewModelFactory(this, viewModelParameters)
else -> DefaultViewModelFactory(this, viewModelParameters)
}
}
I tried setting an initial state with emptyState()
to make sure that viewModelParameters.initialState != null
, and that fixed it. The documentation doesn't mention this though.
The check for viewModelParameters.initialState
was added in commit 47d120c but wasn't there previously.
https://github.com/Kotlin-Android-Open-Source/MVI-Coroutines-Flow/blob/2419ff9e533fdf3d6e42ebdb82b563ac051d66ea/feature-add/src/main/java/com/hoc/flowmvi/ui/add/AddModule.kt#L15
I have used it.get()
instead 😃 and it works
viewModel {
AddVM(
addUser = get(),
savedStateHandle = it.get(),
)
}
@arnaudgiuliani, can you please check this issue? Is there any change that was not documented or this is an actual issue on version 2.2.2?
@hoc081098
https://github.com/Kotlin-Android-Open-Source/MVI-Coroutines-Flow/blob/2419ff9e533fdf3d6e42ebdb82b563ac051d66ea/feature-add/src/main/java/com/hoc/flowmvi/ui/add/AddModule.kt#L15 I have used
it.get()
instead 😃 and it worksviewModel { AddVM( addUser = get(), savedStateHandle = it.get(), ) }
That didn't work for me! :expressionless:
Koin 2.3.0 will bring back separated API for StateViewModel. Documentation is a bit out of date. Just need to finish website and maven central migration.
@arnaudgiuliani, can you please check this issue? Is there any change that was not documented or this is an actual issue on version 2.2.2?
Try to use injected parameters like: {params -> MyViewModel(params.get())}
, to resolve injected params.
Koin 3.0.1 will restore a consistent saveStateViewModel()
API
Koin 2.3.0 will backport new APIs from 3.0.1 to 2.2.x branch
Hi, I'm looking for workaround and I'm not able to find any. Using it.get() cause me a little different error (on both 2.2.2 and 2.2.1 versions):
org.koin.core.error.DefinitionParameterException: No value found for type 'androidx.lifecycle.SavedStateHandle'
Is there any way to make it working without migration to 2.1.x version?
for now, we don't expect to fix 2.x. Koin 3.x will be eligible for LTS
support.
If you need more help, come here: https://github.com/InsertKoinIO/koin/issues/1212
Describe the bug I'm injecting ViewModel with SavedStateHandle, as described in the docs and the blog post about new API in Koin 2.2:
This works in Koin 2.2.1, but in 2.2.2 it crashes with
NoBeanDefFoundException: No definition found for class:'androidx.lifecycle.SavedStateHandle'. Check your definitions!
To Reproduce Check out my sample project
Koin project used and used version:
koin-androidx-viewmodel version 2.2.2
This bug is already mentioned in other issues related to 2.1 -> 2.2 migration, but i think it deserves a thread of its own.
Side note: changelog is missing for 2.2.* versions.