Hi, i was trying to make navigation and i came up ...
# compose
d
Hi, i was trying to make navigation and i came up with this solution: So i have a list of menu items and indexed them
Copy code
val menuItems = listOf("Start", "How to play", "About")
        menuItems.forEachIndexed { index, label ->
            MenuItem(label, index = index, onButtonClicked = { selectedIndex ->
                when(selectedIndex) {
                    0 -> navController.navigate("game_Screen")
                    1 -> navController.navigate("htp_Screen")
                    2 -> navController.navigate("about_Screen")
                }
            }
            )
in my MenuItem i made those elements clickable which calls onButtonClicked(index) In my MainActivity i made a NavHost that looks like this:
Copy code
NavHost(navController = navController, startDestination = "start_Screen") {
                    composable("start_Screen") {
                        NextAppStartingScreen(navController)
                    }
                    composable("game_Screen") {
                        NextApp()
                    }
                    composable("htp_Screen") {
                        HowToPlay()
                    }
                    composable("about_Screen") {
                        AboutScreen()
                    }
                }
My question is, how can i rework this code? Since i know thats not the best solution to it, however with my MenuItem creating elements i thought that its not that bad (It's my first time making any navigation)