Reputation: 3760
I updated the androidx.navigation:navigation-compose
from version 2.5.3 to 2.7.4 and I get the error:Cannot access 'backQueue': it is private in 'NavController'
private fun NavOptionsBuilder.clearBackStack(navController: NavController) {
var firstEntry: String? = null
// first element can be null, we are search for the first non-null one
for (entry in navController.backQueue) {
val route = entry.destination.route
if (route != null) {
firstEntry = route
break
}
}
firstEntry ?: return
popUpTo(firstEntry) {
inclusive = true
}
}
How to do the same thing without the backQueue
?
Upvotes: 1
Views: 770
Reputation: 17
I think
navController.visibleEntries.value
should work, haven't tested yet will see.
Upvotes: 0
Reputation: 11110
Here's an explanation of why backQueue is private:
Source Code for NavController.kt
private val backQueue: ArrayDeque<NavBackStackEntry> = ArrayDeque()
You are trying to access a private
value.
I cannot offer an alternative suggestion because the relevant API was never intended to be public. There are comments to this effect.
Maybe currentBackStackEntry
will do the trick.
Upvotes: 1