hey guys why is this snippet givving an error in v...
# android
a
hey guys why is this snippet givving an error in viewModel() section:
Copy code
composable(route = Screen.GetQuote.route) { navBackStackEntry ->
            val factory = HiltViewModelFactory(LocalContext.current, navBackStackEntry)
            val viewModel: GetQuoteListViewModel = viewModel("GetQuoteListViewModel", factory)
//            val viewModel: GetQuoteListViewModel = viewModel()
            GetQuoteScreen(
                state = viewModel.state.value,
                onClickHome = {
                    navController.navigate("${Screen.Home.route}")
                },
            )
        }
i
If you skip parameters, you need to use named parameters. In your case, you shouldn't be doing any of this at all - just use
hiltViewModel()
as per the docs: https://developer.android.com/jetpack/compose/libraries#hilt-navigation
Copy code
composable(route = Screen.GetQuote.route) { navBackStackEntry ->
            val viewModel: GetQuoteListViewModel = hiltViewModel()
            GetQuoteScreen(
                state = viewModel.state.value,
                onClickHome = {
                    navController.navigate("${Screen.Home.route}")
                },
            )
        }
a
and the factory of the type ViewModelProvider.Factory??
since I need have to pass it as a parameter
i
hiltViewModel()
is already going to use the right factory for Hilt
If you are using Hilt, you should never be touching a Factory 🙂
a
okay let me try it out thanks for the reply