Rodri Represa

    Rodri Represa

    2 years ago
    Do I have to import any specific library to retrieve a ViewModel into a @Composable function? I'm trying to retrieve it and the app crashes
    val viewModel: LoginViewModel by viewModel()
    Colton Idle

    Colton Idle

    2 years ago
    Stacktrace?
    Rodri Represa

    Rodri Represa

    2 years ago
    Maybe I need a ViewModel Factory
    i

    Ian Lake

    2 years ago
    Your ViewModel has to actually extend
    androidx.lifecycle.ViewModel
    Ian Arbuckle

    Ian Arbuckle

    2 years ago
    As Ian said you'll need to import the lifecycle dependency for view model.
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$viewmodel_version")
    Rodri Represa

    Rodri Represa

    2 years ago
    My Viewmodel extends
    androidx.lifecycle.ViewModel
    😐