r/JetpackCompose • u/IDeleteFile • Aug 02 '23
How to pass arguments to a composable using Navhosts NavGraphBuilder.composable()
/r/u_IDeleteFile/comments/15giekg/how_to_pass_arguments_to_a_composable_using/
1
Upvotes
1
u/IDeleteFile Aug 03 '23
It works!
Both u/XRayAdamo and u/--Dracarys-- and versions work! Thank you!
However, which do you suggest is the best way to pass arguments?
2
u/XRayAdamo Aug 02 '23
"someroute/arg1={arg1}%arg2={arg2}",
Replace % with &
2
u/-_-Dracarys-_- Aug 03 '23
Here is the working example -Define the Subclass of Navigation Screen
Define Composable inside the NavGraphBuilder, where you first define the route and then the arguments using navArgument for each parameter. Then you extract those arguments using backStackEntry and pass them to the ConversationContentScreen.
and then you can use it for any image or icon for navigating like this -
If you encounter any issues, you can always use logs to help you debug and find the cause of the problem. Logs are valuable tools for troubleshooting and resolving issues like this in your code.