Colton Idle

01/19/2022, 10:03 PM
Is anyone super familiar with hiltViewModel() and compose nav. Starting to go crazy on this error that it can't create a VM. Am I doing something obvioiusly wrong here?
bottomSheet(route = Screen.DebugBottomSheet.route) {
  DebugBottomSheet(previousScreenVM = hiltViewModel(remember { navController.previousBackStackEntry!! }))
my bottomsheet
fun DebugBottomSheet(
    viewModel: DebugBottomSheetViewModel = hiltViewModel(),
    previousScreenVM: ViewModel,
) {}
java.lang.RuntimeException: Cannot create an instance of class androidx.lifecycle.ViewModel

Albert Chang

01/20/2022, 3:40 AM
You need to specify the class of your view model:

Colton Idle

01/20/2022, 3:49 AM
Is there some way to just get whatever ViewModel is there for the previousBackStackEntry? I'm assuming not... but I figured id ask. back to square 1 it seems.


01/20/2022, 9:19 AM
What are you trying to achieve with that?

Colton Idle

01/20/2022, 7:09 PM
I have a "debug" panel that can essentially draw over top of any of my screens. I want to be able to call certain methods inside of these view models (a la contextual actions from JakeWhartons u2020 debug drawer)
Another potential use case I could come up with though is if I have a common ViewModel. Lets call it MyBaseVM, and I want hiltViewModel to always give me any VM as long as it's MyBaseVM that I use on my screens because there is some common method i want to call.