I had an app made with jetpack compose that worked fine until I upgraded the compose navigation library
from version 2.4.0-alpha07 to version 2.4.0-alpha08
In the alpha08 version it seems to me that the arguments
attribute of the NavBackStackEntry
class is a val
, so it can't be reassigned as we did in the 2.4.0-alpha07 version.
How to solve this problem in version 2.4.0-alpha08?
My navigation component is this:
@Composable
private fun NavigationComponent(navController: NavHostController) {
NavHost(navController = navController, startDestination = "home") {
composable("home") { HomeScreen(navController) }
composable("details") {
val planet = navController
.previousBackStackEntry
?.arguments
?.getParcelable<Planet>("planet")
planet?.let {
DetailsScreen(it, navController)
}
}
}
}
The part where I try to make the navigation happen to the details page is in this function:
private fun navigateToPlanet(navController: NavHostController, planet: Planet) {
navController.currentBackStackEntry?.arguments = Bundle().apply {
putParcelable("planet", planet)
}
navController.navigate("details")
}
I've already tried simply applying to the recurring arguments
of the navigateToPlanet
function using apply
but it doesn't work, the screen opens blank without any information. This is the code for my failed attempt:
private fun navigateToPlanet(navController: NavHostController, planet: Planet) {
navController.currentBackStackEntry?.arguments?.apply {
putParcelable("planet", planet)
}
navController.navigate("details")
}
Planet
object from? What is your single source of truth (your repository, etc.) that you get your Planet objects from? Why doesn't your details destination retrieve the planet from that single source of truth? – DecrescentPlanet
objects come from? What is your single source of truth (your repository)? – Decrescent@Composable private fun PlanetList(navController: NavHostController) { LazyColumn { itemsIndexed(Planet.data) { _, planet -> PlanetCard(planet, navController) } } }
The github link I sent you has more details of the code as a whole. It's a simple code. It's easy to have the general overview – Margarite