https://kotlinlang.org logo
Title
s

Stylianos Gakis

04/11/2023, 5:36 PM
I wonder what this means for the multiplatform-settings. Probably can just stop using that one in favor of just using datastore directly if you prefer that API I assume?
b

bod

04/11/2023, 5:39 PM
Good point! Last time I used DataStore, I wasn't a huge fan as you needed to use protobufs, and that was a bit of a headache 😅
But could be cool to have a look at the Multiplatform version of it
s

Stylianos Gakis

04/11/2023, 5:50 PM
Yeah the protobuf alternative wasn’t that fun to work with in my opinion either. But you can definitely use the one that simply works as a key-value store, and if you want the type-safety, add a layer in-between where you send your stuff in as kotlinx.Serialization capable objects, and then store everything in the datastore as strings. It’s quite nice that way, since you get the type-safety, while also getting a good kotlin-friendly API that works on top of flows/suspending functions for everything.
b

bod

04/11/2023, 5:52 PM
Oh didn't think of using kotlinx serialization, that sounds good!
s

Stylianos Gakis

04/11/2023, 5:57 PM
Yeah me neither, I first read this https://medium.com/androiddevelopers/datastore-and-kotlin-serialization-8b25bf0be66c and I was like: “of course you can do that 🤯” You can do so much with this serialization library. In fact, there’s even a library that is a layer on top of the androidx.navigation library which uses the serialization library to give you nice type-safe destination building https://github.com/kiwicom/navigation-compose-typed. It uses the fact that the classes that are annotated with @Serializable can then be queried for their elements, how they are named, if they are nullable and so on. Also something I never would’ve thought of myself, but it works, and I’ve started using it in our work app recently with great success.
b

bod

04/11/2023, 6:09 PM
Very cool!