0

I have a pretty basic application in Jetpack Compose, where:

  • First screen has a lazyColumn with many items
  • Users can click on an item and be moved to a screen with details about the clicked item
  • Each item is modeled using a data class that is serializable

I've tried passing in the model class with the navigation using:

val modelDataAsString = Json.encodeToString(MODEL_CLASS.serializer(), modelData)
navController.currentBackStackEntry?.arguments?.putString("KEY", modelDataAsString)
navController.navigate("ROUTE/${modelDataAsString}")

But when I do this, I get the following exception:

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

Now, I understood that this is because my Model class in String form is way too long (relevant SO question).

So, searching SO, I found that the solution provided was using a SharedViewModel.

I have done this and everything works well, but something doesn't feel right passing around the viewModel.

What I want to know (and understand) if this is the proper way of solving this issue. I am not looking for an opinion or a recommendation, but a definitive answer.

At the bottom line, what I want to achieve is the ability to allow the onClick method on an item in my LazyColumn move the user to a screen of the item clicked.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
  • Refer to this try: [https://stackoverflow.com/questions/67121433/how-to-pass-object-in-navigation-in-jetpack-compose](https://stackoverflow.com/questions/67121433/how-to-pass-object-in-navigation-in-jetpack-compose) – Halifax Jan 13 '23 at 01:13
  • @Halifax - I have referenced this link in my question and it says there that if your object is too large in String form, you need to use a viewmodel. – tomerpacific Jan 13 '23 at 06:28

0 Answers0