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")
}