https://kotlinlang.org logo
#dagger
Title
# dagger
j

jean

01/13/2022, 1:06 PM
does
hiltViewModel()
supports
@Assisted
constructor attributes now? Or does one still need to use a factory with
@AssistedFactory
?
f

FunkyMuse

01/13/2022, 1:38 PM
You need to use factory, unless you're passing arguments they can be obtained through the savedStateHandle
j

jean

01/13/2022, 1:40 PM
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

FunkyMuse

01/13/2022, 1:58 PM
Yeap you will be fine
j

jean

01/13/2022, 2:54 PM
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

jean

01/13/2022, 3:36 PM
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

Colton Idle

01/13/2022, 6:51 PM
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

rkeazor

01/22/2022, 11:07 PM
I think there is a Memory leak with using @Assisted with HiltViewModel . not sure if they have resolved that issue yet