Anthony
08/10/2021, 3:42 PMAnthony
08/10/2021, 3:44 PM@HiltViewModel
class EditObjectViewModel @Inject constructor(private val savedStateHandle: SavedStateHandle, private val repository: Repository) : ViewModel(){
val object = savedStatHandle.get<long>("objectId")?.let {
repository.getObject(it)
}
}
In the composable I simply had
@Composable
fun ObjectCard(editObjectViewModel : EditObjectViewModel = hiltViewModel()){
}
and in the NavHost
composable(route, arguements = listOf(navArgument("objectId){ type = NavType.LongType}) { backstackEntry -> backStackEntry.arguemnts?.getLong("objectId") ...}
This works and the viewmodel gets the parameter, however when i define the viewmodel in the navigation graph so I can move it to the nested subgraph scope, the viewmodel no longer correctly gets the id.
val editObjectViewModel = hiltViewModel<EditObjectViewModel> (navContrller.getBackStackEntry(nestedGraphRoute))
EditObjectScreen(editObjectViewModel)
Colton Idle
08/10/2021, 3:50 PMAnthony
08/10/2021, 4:11 PMIan Lake
08/10/2021, 4:21 PMAnthony
08/10/2021, 4:23 PM