GitHub
Discussions
Change Log
License
Search…
Overview
Setup
Navigation
ScreenModel
Android ViewModel
Hilt integration
Stack API
State restoration
Transitions
Lifecycle
Back press
Deep links
Powered By
GitBook
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
.
Previous
Android ViewModel
Next
Stack API
Last modified
1mo ago
Copy link
Contents
@Inject
@AssistedInject
Sample