Tlaster / PreCompose

Compose Multiplatform Navigation && State Management

Home Page:https://tlaster.github.io/PreCompose/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can we pass more complex data classes to screen?

PMARZV opened this issue · comments

I have an android app which has compose nav and viewmodels with Saved State Handle which are extracted from the viewmodel to launch some network apis. The object passed by the savestate is a custom dataclass. My question is if theres a method of doing something similar with Precompose (Custom class passed to composable via nav scoped viewmodel and that can be recovered on pop stack). Im somewhat new to compose multi and its quite difficult to join everything (mvvm, navigation, state restoration) together....

PreCompose does not support navigate with complex data, you can check the guide to app architecture and if you follow the guide, you won't need to pass a complex data when navigating I think. And if you really want, you can make you data class to json.

Thanks, i see ill have to pass a json string then! In my app, i need to pass a Song dataclass with its name, artists, popularity,...etc.. thats why i need to pass it to the next screen as a dataclass. If i were to pass only the id of the Song (string), then i would have to do more api calls to get that song data, but it would be inefficient cause i already have some of that data. So instead i pass a complex dataclass (in a json string then) to avoid more api calls!