:wave: I use Compose Multiplatform Navigation v 2....
# compose
h
👋 I use Compose Multiplatform Navigation v 2.8.0-alpha10. My app crashes in runtime due to:
Route …CharacterDetail could not find any NavType for argument id of type …Character.Id - typeMap received was {}
For better perspective see the code:
Copy code
@Serializable
public data class CharacterDetail(val id: Character.Id) 

composable<CharacterDetail> { backStackEntry ->
    val character: CharacterDetail = backStackEntry.toRoute()
    CharacterDetailScreen(character.id, onNavigateBack)
}

public data class Character(id: Character.Id, ...) {
    @Serializable
    public data class Id(val value: Int)
}
Is the @Serializable type safe navigation argument still not supported in CMP?
i
As the error message says, you didn't tell Navigation how to represent your
Character.Id
class. You need to do that if any of the fields in your class aren't primitive types
FWIW, value classes (which you don't seem to be using here, even though it looks like the perfect use case) are supported in the latest point release of the AndroidX artifacts (no idea if there is a CMP version built against it though): https://developer.android.com/jetpack/androidx/releases/navigation#2.8.4
h
Thank you for your answer.
Copy code
@Serializable
public data class Id(val value: Int)
There is only a primitive type inside
Character.Id
class. What I am missing, please? Also, I know a value class would be a perfect match for this use case, but we had some problems using them from the iOS side, so we abandoned them.
i
You need to provide a custom NavType for your class and pass it through the typeMap, like the error says: https://developer.android.com/guide/navigation/design/kotlin-dsl#custom-types
h
Thank you 🙌