Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack compose navigation with multiple optional argments

https://developer.android.com/jetpack/compose/navigation#optional-args

been going through documentation to figure out how to use multiple optional arguments and how to pass them

but in docs only one param is mentioned.

composable(
    "profile?userId={userId}",
    arguments = listOf(navArgument("userId") { defaultValue = "me" })
) 

and call it with

composable("profile")
composable("profile/user123") // if you want to pass param

how to declare and call for two params ?

like image 798
prudhvir3ddy Avatar asked Dec 09 '25 09:12

prudhvir3ddy


1 Answers

how to declare ?

  composable(
    "profile?userId={userId}&userType={userType}",
    arguments = listOf(
      navArgument("userType") {
        defaultValue = "ADMIN"
        type = NavType.StringType
      }, navArgument("userId") {
        nullable = true
        defaultValue = null
        type = NavType.StringType
      })
  ) 

how to call ?

navController.navigate("profile?userId=user123&userType=user")
navController.navigate("profile?userType=user")
navController.navigate("profile")
like image 162
prudhvir3ddy Avatar answered Dec 11 '25 23:12

prudhvir3ddy