我正在尝试通过浮动操作按钮导航到我的 View_Recipe.kt 组合,但它一直在崩溃。这是我的浮动操作按钮和我的 navGraph 代码。
@Composable
fun ActionButton(navController: NavController) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomEnd) {
FloatingActionButton(
modifier = Modifier
.padding(all = 16.dp)
,
onClick = {
navController.navigate(Screens.ViewRecipe.route)
}
) {
Icon(imageVector = Icons.Filled.Add, contentDescription = "Add")
}
}
}
@Composable
fun NavGraph (navController: NavHostController){
val initialDestination = NavDestination.createRoute(Screens.Recipes.route)
/*TODO Fix Composable and constructor*/
NavHost(navController = navController, startDestination = initialDestination)
{
composable(route = Screens.Recipes.route){
Recipes()
}
composable(route = Screens.CulinaryTerms.route){
Culinary_Terms()
}
composable(route = Screens.Drafts.route){
Drafts()
}
composable(route = Screens.IngredientSubstitutions.route){
Ingredient_Substitutions()
}
composable(route = Screens.Settings.route){
Settings()
}
composable(route = Screens.ViewRecipe.route){
View_Recipe()
}
}
}
我不知道要更改什么,但我所知道的是,要么我遗漏了什么,要么我编码错误。