Complete the code to create a NavHost in a Compose UI.
NavHost(navController = [1], startDestination = "home") { composable("home") { HomeScreen() } }
The rememberNavController() function creates and remembers a NavController instance for navigation.
Complete the code to navigate to the "details" screen using NavController.
navController.[1]("details")
The navigate() function is used to move to a different destination in the navigation graph.
Fix the error in the code to get the current back stack entry from NavController.
val currentBackStackEntry = navController.[1]The property currentBackStackEntryAsState provides a state object to observe the current back stack entry in Compose.
Fill both blanks to define a composable destination with a route and content.
NavHost(navController, startDestination = "home") { composable(route = [1]) { [2] } }
The route string must match the destination name, and the composable content is the screen function.
Fill all three blanks to create a NavHost with a remembered NavController and navigate to "profile" on button click.
val navController = [1]() NavHost(navController = navController, startDestination = "home") { composable("home") { Button(onClick = { navController.[2]("profile") }) { Text(text = [3]) } } composable("profile") { ProfileScreen() } }
Use rememberNavController() to create the controller, navigate() to move screens, and a string for button text.