Hi :wave: , I’m using compose multiplatform with c...
# multiplatform
g
Hi 👋 , I’m using compose multiplatform with compose navigation (
org.jetbrains.androidx.navigation:navigation-compose:2.9.1
), but when I can’t get the safe args to work. I’m trying to implement something similar to this: https://medium.com/androiddevelopers/navigation-compose-meet-type-safety-e081fb3cf2f8 🧵
I registered the route with
Copy code
NavHost(
        navController = navController,
        startDestination = NavigationDestination.Home,
        modifier = Modifier.weight(1f)
      ) {
        ...
        composable<Search>(
          typeMap = mapOf(typeOf<SearchParameters>() to SearchParametersType)
        ) { backStackEntry ->
          val searchParameters = backStackEntry.toRoute<Search>().parameters
          Text("Testing: $searchParameters")
        }
     }
but when I navigate I get
Copy code
java.lang.IllegalArgumentException: Navigation destination that matches route com.test.compose.Search/{"searchQuery":"test","filters":[""]} cannot be found in the navigation graph ComposeNavGraph(0x0) startDestination={Destination(0x56174464) route=com.test.compose.NavigationDestination.Home}
If I remove the
typeMap
I get the expected error that it
can't find the NavType for argument parameters of type SearchParameters
, but if I declare the nav type it opens the app, correctly calls the the methods on my custom NavType, but crashes saying that it couldn’t find the destination when I try to navigate
j
It's definitely correct to not specify a type map here. What does your Search class and its dependencies look like? Did you add the kotlinx-serialization plugin to your project?
g
It was an issue with my NavType implementation. I hadn’t implemented the
put
correctly.