Hilt integration
To use the getViewModel you should first import cafe.adriel.voyager:voyager-hilt (see Setup).

@Inject

Add @HiltViewModel and @Inject annotations to your ViewModel.
1
@HiltViewModel
2
class HomeViewModel @Inject constructor() : ViewModel() {
3
// ...
4
}
Copied!
Call getViewModel() to get a new instance.
1
class HomeScreen : AndroidScreen() {
2
3
@Composable
4
override fun Content() {
5
val screenModel = getViewModel<HomeScreenModel>()
6
// ...
7
}
8
}
Copied!

@AssistedInject

Currently there's no Assisted Injection support for Hilt ViewModels (issue).

Sample

Sample code here.