Hello, I’m having this issue when I change between...
# compose
g
Hello, I’m having this issue when I change between dark/light theme:
Copy code
java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.navigation.NavDestination$DeepLinkMatch androidx.navigation.NavGraph.matchDeepLink(androidx.navigation.NavDeepLinkRequest)' on a null object reference
my setup is:
Copy code
setContent {
    val navController = rememberNavController()
    NavHost(navController, startDestination = NavRouting.Home.destination) {
        composable(NavRouting.Home.destination) { ... }
        ...
    }
    navigationManager.commands.collectAsState().value.also { command ->
        if (command.destination.isNotEmpty()) {
            navController.navigate(command.destination) { launchSingleTop = true }
        }
    }
}
Regarding navigation events with
MutableStateFlow
I was inspired by Joe Birch post. What am I doing wrong? 🤔 Thanks.
Well, if I add
collectAsState(NavRouting.Idle)
it fixes it, where
NavRouting.Idle
destination = “”
i
Here's the previous thread about this same problem and an explanation on why Joe's approach is fundamentally flawed (you should not be treating Navigation events as state): https://kotlinlang.slack.com/archives/CJLTWPH7S/p1621016988041000?thread_ts=1621016988.041000&cid=CJLTWPH7S
g
Thanks Ian 🙏 , the NavRouting.Idle was a workaround because I couldn’t solve it, I didn’t remember about
LaunchedEffect