Hilt integration

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


Add @HiltViewModel and @Inject annotations to your ViewModel.
class HomeViewModel @Inject constructor() : ViewModel() {
// ...
Call getViewModel() to get a new instance.
class HomeScreen : Screen {
override fun Content() {
val screenModel = getViewModel<HomeScreenModel>()
// ...


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


Sample code here.