863 B
863 B
Hilt integration
!!! success
To use the getViewModel you should first import cafe.adriel.voyager:voyager-hilt (see Setup).
@Inject
Add @HiltViewModel and @Inject annotations to your ViewModel.
@HiltViewModel
class HomeViewModel @Inject constructor() : ViewModel() {
// ...
}
Call getViewModel() to get a new instance.
class HomeScreen : Screen {
@Composable
override fun Content() {
val screenModel = getViewModel<HomeScreenModel>()
// ...
}
}
@AssistedInject
Currently there's no Assisted Injection support for Hilt ViewModels (issue).
Sample
!!! info Sample code here.