https://kotlinlang.org logo
r

Rodri Represa

09/15/2020, 10:45 AM
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
Copy code
val viewModel: LoginViewModel by viewModel()
c

Colton Idle

09/15/2020, 1:19 PM
Stacktrace?
1
r

Rodri Represa

09/15/2020, 2:47 PM
Maybe I need a ViewModel Factory
i

Ian Lake

09/15/2020, 3:45 PM
Your ViewModel has to actually extend
androidx.lifecycle.ViewModel
👍 1
i

Ian Arbuckle

09/15/2020, 4:47 PM
As Ian said you'll need to import the lifecycle dependency for view model.
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$viewmodel_version")
r

Rodri Represa

09/16/2020, 9:27 AM
My Viewmodel extends
androidx.lifecycle.ViewModel
😐