When I click on any of my BottomNavigation items I get an IllegalStateException
.
This is my initial code that I expected to work
BottomNavigation(contentColor = colorResource(id = R.color.white)) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
menuItems.forEach {
BottomNavigationItem(
label = {Text(text=it.title)},
alwaysShowLabel = true,
selectedContentColor = Color.White,
unselectedContentColor = Color.Gray,
selected = currentRoute == it.route,
onClick = {
navController.navigate(it.route) {
navController.graph.startDestinationRoute?.let {
route ->
popUpTo(route) {
saveState = true
}
}
launchSingleTop = true
restoreState = true
}
},
icon= {Icon(imageVector = it.icon, contentDescription = it.title)}
)
}
}
I tried different variations of the code from the web but they all throw the same exception
Also tried setting alwaysShowLabel
to false