https://kotlinlang.org logo
#compose
Title
# compose
m

manueldidonna

11/16/2020, 3:22 PM
I'm exploring the navigation library with compose, I get that the navigation is string based, so any arguments I want to pass to the composable must be inserted in the route string. I have 2 screens. In the first screen the user creates a
SearchRequest
to pass to the second screen that uses it to fetch the items from a web server.
Copy code
data class SearchRequest(
    val departFrom: String,
    val arriveAt: String,
    val departureTime: Time, // data class with day, month and year
    val departureDate: Date // data class with minute and hour
)
What's the best way to translate this object to a route without parcelizing it?
🤯 1
r

Rajan Kali

11/17/2020, 5:52 AM
If you do not want to use Parcel, then I would suggest to go for JSON String , convert it to json and pass it as String and parse it back to class
m

manueldidonna

11/17/2020, 11:05 AM
Here is what I've done
Copy code
// route = "solutions/{departure}/{arrival}/{datetime}"
val navigationArguments = navBackStackEntry.arguments ?: bundleOf()
val departure = navigationArguments.getString("departure", "")
val arrival = navigationArguments.getString("arrival", "")
val datetime = LocalDateTime.parse(navigationArguments.getString("datetime", ""))
3 Views