Marcin Mazurek
06/16/2021, 11:03 AMNavHost(startDestination = "profile/{userId}") {
...
composable("profile/{userId}") {...}
}
Hello how to pass argument to navhost start destinationhfhbd
06/16/2021, 11:17 AMMarcin Mazurek
06/16/2021, 11:29 AMSe7eN
06/16/2021, 11:36 AMstartDestination = "profile/42"
. Replace 42 with your user idMarcin Mazurek
06/16/2021, 11:37 AMNavHost(
navController,
startDestination = "profile/1234"
) {
composable("profile/{userId}", listOf(navArgument("userId") { type = NavType.StringType })){
val test =
it.arguments?.getString("userId").orEmpty()
Timber.e("ProductListFeature" + " "+ test)
}
}
i wrote some basic code, and i got the error navigation destination 1450140917 is not a direct child of this NavGraphhfhbd
06/16/2021, 11:47 AMNavHost(
navController,
startDestination = "profile/1234"
) {
composable("profile/{userId}") {
val test = it.arguments?.getString("userId").orEmpty()
Timber.e("ProductListFeature" + " "+ test)
}
}
Marcin Mazurek
06/16/2021, 12:00 PMMarcin Mazurek
06/16/2021, 12:16 PMIan Lake
06/16/2021, 1:53 PMstartDestination
needs to match the string in the route
exactly, you can't use that to provide default values for arguments. Instead, use the actual APIs for defining default values of arguments:
composable("profile/{userId}",
arguments = listOf(navArgument("userId") { defaultValue = "1234" }) {
}
Marcin Mazurek
06/16/2021, 1:54 PMIan Lake
06/16/2021, 1:56 PMIan Lake
06/16/2021, 1:56 PMMarcin Mazurek
06/16/2021, 2:00 PMMarcin Mazurek
06/16/2021, 2:07 PMIan Lake
06/16/2021, 2:13 PMMarcin Mazurek
06/16/2021, 2:18 PMMarcin Mazurek
06/16/2021, 2:20 PMMarcin Mazurek
06/16/2021, 3:28 PMNavGraphBuilder.moduleNameGraph(NavController)
but i have concern about it. How can i create shared view model hiltViewModel
- i must do it in composable function so then i must create and pass this viewmodel as parameter of moduleNameGraph it's not looks niceIan Lake
06/16/2021, 3:40 PMhiltViewModel(navController.getBackStackEntry(sharedGraphRoute)))
away from getting that ViewModel where you need itMarcin Mazurek
06/16/2021, 6:14 PMIan Lake
06/16/2021, 6:21 PMMarcin Mazurek
06/16/2021, 6:23 PMhttps://c.tenor.com/3eIvVsG3yPYAAAAM/the-universe-tim-and-eric-mind-blown.gif▾
Marcin Mazurek
06/16/2021, 6:27 PM