Christopher Mederos
10/28/2024, 11:47 PM// is there an optional version of the toRoute() ext fun?
data class NewPost
data class EditPost(val id: Int)
private val editPost : EditPost? = savedStateHandle.toRoute()
if (editPost != null) { initStateWithExistingData(editPost.id) }
// should a single destination type be used instead?
data class Post(val existingId: Int?)
private val post : Post = savedStateHandle.toRoute()
if (post.existingId != null) { initStateWithExistingData(post.existingId) }
Stylianos Gakis
10/28/2024, 11:50 PMtoRoute()
on the graph, and as you call by viewModel()
pass in there as a param the ID you want to be provided to the constructor of your VM.
Then you won't be getting it from the SSH, but it's the same source of truth, the navigation parameters