how can i read the nav arguments in a route (using...
# compose
a
how can i read the nav arguments in a route (using the cmp navigation lib)) If i do
backStackEntry.arguments
it gives me
SavedState
which has no getters I know I can use the serialization way, but it doesn't fit my use case.
Ok figured it out.
Copy code
val orderId = entry.savedStateHandle.get<String>("orderId")!!
not
Copy code
entry.arguments.get<String>("orderId")!!
s
Yes, and we can use this way as well :
Copy code
entry.arguments?.read { getString("orderId") } ?: ""
a
why would i want the one over the other?
i
Forcing everything into a SavedStateHandle means you'll have two copies in savedstate and is really only appropriate if you need an editable version (e.g., removing a key after you read it to only process it once), using the SavedStateReader APIs via
.read
is the correct way to read keys from a SavedState
👀 1