According to the docs, the non-DI way to associate an view model with an @Composable
is via the viewModel()
function from androidx.lifecycle.viewmodel.compose.viewModel
, like this:
@Composable
fun ProfileScreen(val viewModel: ProfileViewModel = viewModel() {
...
But if your view model requires dependencies, you have to pass a subclass of ViewModelProvider.Factory
that holds the dependency and knows how to construct the view model for you. Like this: