Is there a way to get destination argument names f...
# compose-destinations
m
Is there a way to get destination argument names from the generated code? E.g. I'd like to access a key in the savedStateHandle retrieved in a ViewModel without having to hardcode the argument name
Copy code
fun SomeDestination(val arg1: Long, val someString: String) {}
class MyViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
    val someString = savedStateHandle.get(SomeDestinationArgumentKeys.SomeString)
}
r
Why would you want to do that? You can get all the arguments and then access them in a type safe manner 🤔
m
How? 😛
ProfileScreenDestination.argsFrom(handle) ?
r
Copy code
val navArgs = handle.navArgs<MyDestinationArgs>()

OR

val navArgs: MyDestinationArgs = handle.navArgs()
or using argsFrom method directly, yes 🙂
m
Nice, I had not found that yet 😅
🙌 1