https://kotlinlang.org logo
#compose
Title
# compose
b

brabo-hi

01/27/2022, 11:27 PM
Hi all, from the doc
<https://developer.android.com/guide/navigation/navigation-pass-data#supported_argument_types>
navigation can accept a nullable string as parameter. Should we ignore the null argument ?
Copy code
composable(route = "person/{id}") {
            val id = it.arguments?.getString("id") // here i am getting the word `null` as as string instead of String? = null 
        }
        navController.navigate("person/${null}")
i

Ian Lake

01/27/2022, 11:31 PM
If you navigate to
person/null
, you will get the ID of
null
, just like you said it should be; there's no string interpretation being done for path parameters (which are always required parameters). Optional arguments are in the form of query parameters (where what you'd navigate to is
person
, which would match a route of `person?id={id}`: https://developer.android.com/jetpack/compose/navigation#optional-args
b

brabo-hi

01/27/2022, 11:36 PM
so basically i need to pass them as optional parameters and set them as nullable = true ?
i

Ian Lake

01/27/2022, 11:44 PM
that's exactly what the section labeled "Adding optional arguments" says, yes
1