https://kotlinlang.org logo
#compose
Title
# compose
l

loloof64

07/23/2022, 3:43 PM
Hi. I'm using Android Studio Chipmunk. I can't call `viewModel()`in a `@Composable`parameter, though I've added the dependency
androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0
to build.gradle file of the app module. Why ? (I keep getting the error "Expression 'viewModel' of type 'StockfishLibraryViewModel' cannot be invoked as a function. The function 'invoke()' is not found")
This is the viewModel I'm trying to use.
i

Ian Lake

07/23/2022, 3:50 PM
Show your code where you are using
viewModel()
l

loloof64

07/23/2022, 3:51 PM
This is the whole file
i

Ian Lake

07/23/2022, 3:55 PM
You haven't imported the
viewModel()
function:
import androidx.lifecycle.viewmodel.compose.viewModel
1
👍🏾 1
l

loloof64

07/23/2022, 3:55 PM
This is the build file.
Thank you very much 🙂
i

Ian Lake

07/23/2022, 3:56 PM
So it thinks you are calling the
invoke()
method on your variable named
viewModel
when you add the parentheses after the variable name
The easiest way to figure that out is to rename that variable
👍 1
l

loloof64

07/23/2022, 3:56 PM
Ok, I understand better 🙂
Next time I'll start with a different name than viewModel for my parameter 🙂
154 Views