Hi where is this : koinNavGraphViewModel ? I'm usi...
# koin
p
Hi where is this : koinNavGraphViewModel ? I'm using koin 3.1.6 but this function not exists
c
You need to add a dependency to
Copy code
implementation "io.insert-koin:koin-androidx-navigation:$koin_version"
p
Thanks I’ve got an error with SaveStateHandle no definition found. but it works if I change koinNavGraphViewModel and add stateResgistry parameter
Copy code
@OptIn(KoinInternalApi::class)
inline fun <reified VM : ViewModel> Fragment.koinNavGraphViewModel(
    @IdRes navGraphId: Int,
    noinline bundleDefinition: BundleDefinition? = emptyState(),
    noinline parameters: ParametersDefinition? = null
): Lazy<VM> {
    val backStackEntry: NavBackStackEntry by lazy { findNavController().getBackStackEntry(navGraphId) }
    val owner = {
        ViewModelOwner(
            storeOwner = backStackEntry,
            stateRegistry = backStackEntry
        )
    }
    val scope = getKoinScope()
    return viewModels(ownerProducer = { backStackEntry }) {
        getViewModelFactory(
            owner = owner,
            qualifier = null,
            parameters = parameters,
            scope = scope,
            state = bundleDefinition,
            clazz = VM::class
        )
    }
}
Copy code
val owner = {
        ViewModelOwner(
            storeOwner = backStackEntry,
            stateRegistry = backStackEntry
        )
    }
209 Views