AN
08/09/2022, 8:36 PMjava.lang.IllegalArgumentException: Wrong argument type for 'userId' in argument bundle. integer expected.
code:
object ProfileDestination : GenericDestination {
override val route = "profile_route/{userId}"
override val startDestination = "profile_destination/{userId}"
const val argsUserId = "userId"
operator fun invoke(id: Int) = "profile_route/$id"
}
fun NavGraphBuilder.profileGraph() {
navigation(startDestination = ProfileDestination.startDestination, ProfileDestination.route) {
composable(
route = ProfileDestination.startDestination,
arguments = listOf(navArgument(ProfileDestination.argsUserId) {
type = NavType.StringType
})
) { Profile() }
}
}
navController.navigate(ProfileDestination(1))
Ian Lake
08/10/2022, 11:27 PMnavigation
element), which doesn't have any arguments
defined, so you're just getting the default, which is strings. Generally, you'll want to navigate directly to the destination rather than to a navigation graph:
operator fun invoke(id: Int) = "profile_destination/$id"
profileGraph
could just be a single composable
destination, skipping the intermediate layer entirely?AN
08/11/2022, 11:45 AMIan Lake
08/11/2022, 4:02 PMAN
08/12/2022, 9:35 AM