I am trying to use Android Compose Type Safe navigation but I got this error.
How do i solve it?
The objects:
@Serializable
data object MainScreen {
@Serializable
data class MainScreenFirstScreen(val id: Int? = null)
}
I have to navigate to the MainScreen passing in id from another screen
FirstLoginOwnerSixthScreenRoot(
onNavigateToNextScreen = { id ->
navHostController.navigate(
route = MainScreen.MainScreenFirstScreen(
id = id
)
)
The Graph:
fun NavGraphBuilder.mainScreenOwnerNavGraph() {
navigation<MainScreen>(
startDestination = MainScreen.MainScreenFirstScreen()
) {
composable<MainScreen.MainScreenFirstScreen> { navBackStackEntry ->
val navHostController = LocalNavHostContoller.current
Text("Main Screen")
}
}
}
But I got the following error:
kotlinx.serialization.SerializationException: Serializer for class 'MainScreen' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
I do similar things elswhere in the app and nowhere else is a problem
1