gpt4 book ai didi

kotlin - 如何从 Compose-Navigation 中的返回堆栈中删除可组合项

转载 作者:行者123 更新时间:2023-12-04 07:44:20 30 4
gpt4 key购买 nike

我的应用程序中有一个屏幕,允许用户编辑数据库中的项目,在用户完成编辑项目后,他们单击“完成”按钮,将他们带到上一个屏幕。
但是当用户单击后退按钮时,他们将再次转到编辑屏幕。
我想要的是当用户单击后退按钮时会转到另一个屏幕,就像他们从未去过编辑屏幕一样。
这是我的导航图:

@Composable
fun AppNavigator(
textFieldsViewModel: TextFieldsViewModel,
shoppingListsViewModel: ShoppingListsViewModel,
addNewShoppingListViewModel: AddNewShoppingListViewModel
) {

val navController = rememberNavController()

NavHost(navController, startDestination = "SplashScreen") {
composable("SplashScreen") {
SplashScreen(navController = navController)
}
composable("shoppingLists") {
ShoppingListsScreen(
navController = navController,
shoppingListsViewModel = shoppingListsViewModel,
textFieldsViewModel = textFieldsViewModel
)
}
composable(
"ItemsList/{listID}",
arguments = listOf(navArgument("listID") { type = NavType.IntType })
) {
ShoppingListItemsScreen(
it.arguments?.getInt("listID")!!,
shoppingListsViewModel = shoppingListsViewModel,
textFieldsViewModel = textFieldsViewModel,
navController = navController
)
}
composable(
"EditItem/{itemId},{itemName},{itemQuantity},{itemParentListId}",
arguments = listOf(
navArgument("itemId") { type = NavType.IntType },
navArgument("itemName") { type = NavType.StringType },
navArgument("itemQuantity") { type = NavType.IntType },
navArgument("itemParentListId") { type = NavType.IntType })
) {
EditItemScreen(
navController = navController,
textFieldsViewModel = textFieldsViewModel,
shoppingListsViewModel = shoppingListsViewModel,
itemId = it.arguments?.getInt("itemId")!!,
itemName = it.arguments?.getString("itemName")!!,
itemQuantity = it.arguments?.getInt("itemQuantity")!!,
itemParentListId = it.arguments?.getInt("itemParentListId")!!
)
}
composable("AddNewShoppingList") {
AddNewShoppingListScreen(
navController = navController,
textFieldsViewModel = textFieldsViewModel,
addNewShoppingListViewModel = addNewShoppingListViewModel,
shoppingListsViewModel = shoppingListsViewModel
)
}

}
}
这是负责导航到前一个可组合的按钮的代码:
 IconButton(
onClick = {
shoppingListsViewModel.addNewItemToShoppingList(item)
navController.navigate("ItemsList/${changeableParentListId.value}")
}) {
Icon(Icons.Rounded.Done, "Save or Edit the Shopping Item")
}
这是编辑屏幕的屏幕截图:
enter image description here

最佳答案

从编辑/详细信息屏幕,您应该调用 navController.popBackStack() .

关于kotlin - 如何从 Compose-Navigation 中的返回堆栈中删除可组合项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67272453/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com