commandiron
commandiron

Reputation: 1473

Android Jetpack navigation - How to pass empty string in navigation arguments?

AnimatedNavHost(navController, startDestination = BottomNavItem.Splash.screen_route){
composable(
            signup + "/{emailFromSignIn}" + "/{passwordFromSignIn}",
            arguments = listOf(
                navArgument("emailFromSignIn"){
                    type = NavType.StringType
            },navArgument("passwordFromSignIn"){
                    type = NavType.StringType
            }
}
navController.navigate(signup + "/$textEmail" + "/$textPassword")

How can I pass an empty string?

Error:

Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/signup// } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0xb6b16c34) route=splash}

Upvotes: 5

Views: 2908

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 87814

You can use an optional parameter with default empty string value:

composable:

composable(
    route = "$signup?emailFromSignIn={emailFromSignIn}&passwordFromSignIn={passwordFromSignIn}",
    arguments = listOf(
        navArgument("emailFromSignIn"){
            type = NavType.StringType
            defaultValue = ""
        },navArgument("passwordFromSignIn"){
            type = NavType.StringType
            defaultValue = ""
        }
    )
) {

navigate:

navController.navigate("$signup?emailFromSignIn=$textEmail&passwordFromSignIn=$textPassword")

Upvotes: 6

Related Questions