Joost Klitsie
03/07/2025, 9:42 AMnavigation<MyGraph> {}
supports the same type safe objects. I was hoping we can simply access the back stack entry for that and then read out the data we passed (more in the comment).
Is this possible?Joost Klitsie
03/07/2025, 9:42 AM@Serializable
data class MyGraph(val text: String) {
@Serializable
data object Start
}
fun NavGraphBuilder.registerTestGraph(navController: NavController) {
navigation<MyGraph>(
startDestination = MyGraph.Start,
) {
composable<MyGraph.Start> {
val route = remember { navController.getBackStackEntry<MyGraph>().toRoute<MyGraph>() }
Text(route.text)
}
}
}
Joost Klitsie
03/07/2025, 9:43 AMnavController.navigate(MyGraph("test"))
it will crash at the line where I try to resolve the route, as the field text
cannot be foundJoost Klitsie
03/07/2025, 9:43 AMJoost Klitsie
03/07/2025, 12:41 PMJoost Klitsie
03/07/2025, 12:45 PM@Serializable
data class MyGraph(val text: String) {
@Serializable
data class Start(val text: String)
}
fun NavGraphBuilder.registerTestGraph(navController: NavController) {
navigation<MyGraph>(
startDestination = MyGraph.Start::class,
) {
composable<MyGraph.Start> { entry ->
val route = remember { entry.toRoute<MyGraph.Start>() }
Text(route.text)
}
}
}
Simply add the parameters to both the graph and the destination and then they get passed 😄 amazing