androidandroid-jetpack-composekoin

Koin inject viewmodel into Composable


I am trying to use Koin to inject my viewModel (which has some dependencies as well) like this:

Unresolved Reference

I don't understand why it cannot find getViewModel when I have the following import:

Koin import

I am using this Koin version: implementation "io.insert-koin:koin-android:$koin_version"

where $koin_version = '3.2.0-beta-1'

Any thoughts why my import is ignored here?


Solution

  • You're using a wrong import, you should use:

    import org.koin.androidx.compose.getViewModel
    

    To use it you need the following dependency:

    implementation("io.insert-koin:koin-androidx-compose:$koinVersion")