Hello, I am facing a problem when passing a list o...
# compose
a
Hello, I am facing a problem when passing a list of strings, that are links, through compose navigation with type safety due to the links containing "/" and causing unknown destination crash
anyone know a smart way to handle such cases
is something like
Copy code
val encodedUrl = URLEncoder.encode("<http://alphaone.me/>", StandardCharsets.UTF_8.toString())
navController.navigate("HistoryDetail/$encodedUrl")
with type safety, is considered ok?
s
This doesn't look like it's using the type-safe approach of the navigation library. You seem to be navigating using strings instead of creating an object and passing it to .navigate()
a
I used a stackoverflow example of how people overcome this
Even with type safety typemaps you have to do this
basically if a string contains a "/" you must replace it otherwise it will cause crashes
s
Yeah but there things are simple, you only need to make sure to Uri.encode your String inside the "serializeAsValue" function. Here's where we do it. As called out very specifically in the documentation too: https://developer.android.com/guide/navigation/design/kotlin-dsl#custom-types
a
Thank you for the material, this is what i needed 🙂
blob hug 1