oday
02/22/2024, 11:44 AMfun NavHostController.navigateBookDetail(
bookId: Long,
bookTitle: String
) {
setState("bookId", bookId)
setState("bookTitle", bookTitle)
navigate(Routes.Slave.BookDetail.path)
}
composable(Routes.BookDetail.path) {
val bookId = navController.getBookIdStateFromState()
val bookTitle = navController.getBookTitleFromState()
BookDetailScreen(
bookId = bookId,
bookTitle = bookTitle,
)
}
@HiltViewModel
class BookDetailViewModel @Inject constructor(
private val snippetRepository: SnippetRepository,
savedStateHandle: SavedStateHandle
) : ViewModel() {
init {
val bookid = savedStateHandle.get<Long>("bookId")
val bookTitle = savedStateHandle.get<String>("bookTitle")
}
}
I'm getting back null in the viewmodel, the only way this would work if I have BookDetail/{bookId}/{bookTitle}
AND I set the arguments as navArgs in the composable
but can I not do the above and still get back the values in the statehandle? I don't want to send them in the "normal" way for exampleIan Lake
02/22/2024, 3:06 PModay
02/22/2024, 3:11 PMIan Lake
02/22/2024, 3:25 PModay
02/22/2024, 3:41 PM