I have a fragment which basically only holds a bottomnavigation and a viewmodel. This viewmodel is shared by all the childfragments in this fragment. My parentfragment looks a bit like this:
class UserDetailFragment : Fragment() {
private val args: UserDetailFragmentArgs by navArgs()
private val userDetailViewModel: UserDetailViewModel by viewModel { parametersOf(args.user) }
//standard code
//onCreateActivity where I do some basic stuff like switching the fragments
}
The viewmodel is registered in koin like so:
val viewModelModule = module {
/* other viewmodels */
viewModel { (user: UserModel) -> UserDetailViewModel(get(), get(), user) }
}
Then we have the childfragments which I'm trying to define like this:
class UserAlbumsFragment : Fragment() {
private val userDetailViewModel: UserDetailViewModel by sharedViewModel() //THIS LINE ISN'T WORKING
//standard code again
}
As you can see one line isn't working, I tried writing it as:
private val userDetailViewModel: UserDetailViewModel
by sharedViewModel(from = { parentFragment as ViewModelStoreOwner })
but I keep getting this error:
Caused by: org.koin.core.error.NoParameterFoundException: Can't get parameter value #0 from org.koin.core.parameter.DefinitionParameters@426de94
at org.koin.core.parameter.DefinitionParameters.elementAt(DefinitionParameters.kt:31)
at org.koin.core.parameter.DefinitionParameters.component1(DefinitionParameters.kt:33)
at com.kvw.technicaltestmediamonks.di.KoinModules$viewModelModule$1$5.invoke(Unknown Source:11)
at com.kvw.technicaltestmediamonks.di.KoinModules$viewModelModule$1$5.invoke(KoinModules.kt:37)
at org.koin.core.instance.DefinitionInstance.create(DefinitionInstance.kt:54)
How do I get this viewmodel without defining the userModel again?