I am trying to set up the navigation back button following this SO thread, but can't make it work.
@ExperimentalFoundationApi
@Composable
fun LazyVerticalGridActivityScreen() {
val navController = rememberNavController()
val navigationIcon: (@Composable () -> Unit)? =
if (navController.previousBackStackEntry != null) {
{
IconButton(onClick = { navController.popBackStack() }) {
Icon(imageVector = Icons.Filled.ArrowBack, contentDescription = null)
}
}
} else {
null
}
Scaffold(
topBar = {
TopAppBar(title = { Text("Lazy Vertical Grid") }, navigationIcon = navigationIcon)
},
content = {
NavHost(navController = navController, startDestination = "home") {
composable("home") { HomeScreen(navController) }
composable("details/{listId}") { backStackEntry ->
backStackEntry.arguments?.getString("listId")
?.let { DetailsScreen(it, navController) }
}
}
}
)
}
Can anyone please help to fix this? Thanks!