I'm trying to display a welcome message on the Dashboard to the user when he can from the welcome page. So, in my route for the Dashboard, I defined a optional argument.
It's working fine to access it without any argument (because, it's optional) but when I add one, it's not working anymore.
composable(Routes.welcome) {
WelcomeScreen {
navController.navigate("dashboard?isWelcome={true}")
}
}
composable(
"dashboard?isWelcome={isWelcome}}",
arguments = listOf(
navArgument("isWelcome") {
type = NavType.BoolType
}
)
) {
val isFromWelcome = it.arguments?.getBoolean("isWelcome") ?: false
...
}
The error I have :
Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/dashboard?isWelcome={true} } cannot be found in the navigation graph
Thanks for your advice :)
val booleanValue = true
navController.navigate("my_destination?my_arg_id=${booleanValue}")
composable(
route = "my_destination?my_arg_id={my_arg_id}",
arguments = listOf(navArgument("my_arg_id") { defaultValue = false })
) { from ->
val myBooleanArg = from.arguments?.getBoolean("my_arg_id")
MySecondScreen(myBooleanArg)
}
2024 Update: You can use the Type Safe navigation now. More information about it here