Skip to content

Instantly share code, notes, and snippets.

@GMetaxakis
Last active May 20, 2022 06:21
Show Gist options
  • Save GMetaxakis/77c0973070ca67f501da19189846e3b1 to your computer and use it in GitHub Desktop.
Save GMetaxakis/77c0973070ca67f501da19189846e3b1 to your computer and use it in GitHub Desktop.
Profile & ProfileArgType
data class Profile(val firstName:String, val lastName:String){
override fun toString(): String = Uri.encode(Gson().toJson(this))
}
class ProfileArgType : JsonNavType<Profile>() {
override fun fromJsonParse(value: String): Profile = Gson().fromJson(value, Profile::class.java)
override fun FromProfileArguments.getJsonParse(): String = Gson().toJson(this)
}
//Discaimer : Gson or Moshi or any other library is up to you
NavHost(navController = navController, startDestination = "profile"){
/*...*/
composable(
route="friendprofile/{profile}",
arguments = listOf(navArgument("profile"){
type = ProfileArgType()
})
) { navBackStackEntry->
val profile = navBackStackEntry.arguments?.getString("profile")?.let { Gson().fromJson(it, Profile::class.java) }
FriendProfile(navController, profile)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment