我有一个重定向到食品的可点击行:
.clickable {
// Navigate to FoodProductsScreen when clicked
Log.d("Navigation", "Category ID: ${category.id}")
navController.navigate("${NavGraph.FoodProducts}?categoryId=${category.id}")
},`
字符串
当我在这里打印category.id时,它在控制台上记录2,但当我在NavHost中打印它时,它说0:
`
composable(NavGraph.FoodProducts) { backStackEntry ->
val categoryId = backStackEntry.arguments?.getInt("categoryId") ?: 2
Log.d("Navigation", "Received Category ID: $categoryId")
FoodProductsScreen(navController, categoryId)
}`
型
食品屏幕:
`@Composable
fun FoodProductsScreen(navController: NavController, categoryId: Int) {
val productsInCategory = products.filter { it.id == categoryId }
Column(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
) {
Text(text = "${categoryId}")
}
LazyColumn {
items(productsInCategory) { product ->
FoodProductItem(product = product)
}
}
}`
型
我试过很多方法但都不管用...
我试着像这样从最后一个视图中检索参数:FoodProductsScreen(navController, backStackEntry.arguments?.getInt("categoryId") ?: 1)
,但它不起作用。
1条答案
按热度按时间k2arahey1#
字符串
你能试试这个吗?