does `hiltViewModel()` supports `@Assisted` constr...
# dagger
j
does
hiltViewModel()
supports
@Assisted
constructor attributes now? Or does one still need to use a factory with
@AssistedFactory
?
f
You need to use factory, unless you're passing arguments they can be obtained through the savedStateHandle
j
yes I’m reading about it in here https://github.com/google/dagger/issues/2287. I just need an id, so I guess I’ll be fine with savedStateHandle
f
Yeap you will be fine
j
I getting a bit stuck there though :
Copy code
val viewModel by viewModel(
    factory = MyViewModel.provideFactory(...),
)
How do I get an instance of
AbstractSavedStateViewModelFactory
from a composable function? Since I cannot do `
Copy code
@Inject
lateinit var plantDetailViewModelFactory: PlantDetailViewModelFactory
like from an activity or a component?
j
I figured it out, I can simply use
hiltViewModel()
and navigation arguments are directly passed to the handle. That’s really nice but a bit confusing to understand 🙂
c
Yeah. I think I filed a bug about this so the docs would be updated but I dont think I got any traction.
took me way too long to realize it just works. lol
Please comment or just file the same "docs missing" bug. i really dont understnad why my ticket was closed. /shruggie
r
I think there is a Memory leak with using @Assisted with HiltViewModel . not sure if they have resolved that issue yet