0

我正在用 compose 开发副项目,我对 Compose 导航很感兴趣。我想要的是将 Parcelable 对象从一个可组合屏幕传递到另一个屏幕。所以导航是这样的:

composable(
        route = Screen.DetailsScreen.route,
        arguments = navArgument(PARAMETER_MOVIE_KEY) {
            NavType.ParcelableType(Movie::class.java)
        }
    ) {
        DetailsScreenGuide(navController, it)
    }

从主屏幕导航时,我将 parcelable 对象放入NavController.currentBackStackEntry.

navController.currentBackStackEntry?.arguments?.putParcelable(
    "movieArgument",
    homeScreenNavGraphDataModel.movie
)
navController.navigate(route) // here, route = "movieDetails/movie"

然后,在调用 MovieDetails 可组合屏幕之前,我尝试从navController.previousBackStanEntry.

val movie = remember {
    navController.previousBackStackEntry?.arguments?.getParcelable<Movie>(
        "movieArgument"
    )
}

但在这里,movie变量为空,我无法接收对象。(导航正在工作,它正在膨胀 MovieDetails 可组合功能

你能帮我调试这些代码片段还是我在某个地方弄错了?

4

0 回答 0