Rohan Maity
08/14/2022, 4:26 AMitnoles
08/14/2022, 4:37 AMRohan Maity
08/14/2022, 4:39 AMIan Lake
08/14/2022, 5:48 AMRohan Maity
08/14/2022, 6:01 AMfragment<F>(route)
then this route should be format
"baseRoute/{permanent_arg1_name}/{permanent_arg_2_name}?optionalArg1Name={optionalArg1Name}&optionalArg2Name={optionalArg2Name}"
This because when fragment destination is built, it uses the argument name to build the route and when you route using navigate(), one has to pass the values for placeHolder so that they can match against values with which route has been created
Notice how the name as been used for optionalArgs as well this because and argument is built with this very name in fragment dsl, so when building route, use the very same name for placeHolders even in optionalArgs (just like normal args)Ian Lake
08/14/2022, 6:03 AMoptionalArg1Name=
could be any key; Nothing cares what that key isIan Lake
08/14/2022, 6:04 AMRohan Maity
08/14/2022, 6:04 AM{}
Ian Lake
08/14/2022, 6:04 AMIan Lake
08/14/2022, 6:05 AMIan Lake
08/14/2022, 6:07 AMIan Lake
08/14/2022, 6:08 AMRohan Maity
08/14/2022, 6:13 AMfragment<PlantDetailFragment>("${nav_routes.plant_detail}?plant_id="{${nav_arguments.plant_id}}") {
label = resources.getString(R.string.plant_detail_title)
argument(nav_arguments.plant_id) {
type = NavType.StringType
}
}
then the name used in argument building should match the one in fragment destination route building in placeHolders (ones in curly braces {}
) so that arguments when passed during navigating using navigate()
could match the proper placeholdersIan Lake
08/14/2022, 6:14 AM${random_kotlin_code}
syntax is part of Kotlin, you're not actually putting any braces in your actual string in that codeIan Lake
08/14/2022, 6:15 AMIan Lake
08/14/2022, 6:15 AMfragment
method is a different method than the composable
one thoughRohan Maity
08/14/2022, 6:16 AMTheI am sorry I added them now here is the updated stringsyntax is part of Kotlin, you're not actually putting any braces in your actual string in that code${random_kotlin_code}
"${nav_routes.plant_detail}?plant_id="{${nav_arguments.plant_id}}"
Notice the extra {}
it was after this navigation dsl worksIan Lake
08/14/2022, 6:19 AMRohan Maity
08/14/2022, 6:22 AMAnd the Compose DSL is literally the same DSL. There is only one DSL 🙂Yes, after going through compose, one can infer this, but IMHO, • there should have been section of optional args in Navigation kotlin dsl (not compose one) or atleast a link referring to compose doc. • Also documentation of Navigation kotlin dsl is kinda incorrect here: https://developer.android.com/guide/navigation/navigation-kotlin-dsl#navgraphbuilder. It does not tell about those extra
{}
I agree so far people have figured out on their own or through compose, but I think this should be fixed as wellIan Lake
08/14/2022, 6:24 AMIan Lake
08/14/2022, 6:25 AMRohan Maity
08/14/2022, 6:27 AMIan Lake
08/14/2022, 6:29 AMRohan Maity
08/14/2022, 6:29 AM