russhwolf / multiplatform-settings

A Kotlin Multiplatform library for saving simple key-value data
Apache License 2.0
1.69k stars 67 forks source link

[Question] How to use FlowSettings #90

Closed fodeguirassy closed 2 years ago

fodeguirassy commented 3 years ago

Hello

Thanks for this great library you're shipping to us.

I was looking for a basic usage of FlowSettings. I tried the following but getting errors.

Screenshot 2021-07-20 at 15 01 25

Thanks for your help !

russhwolf commented 3 years ago

What are the errors you're getting?

Try

val flowSettings: FlowSettings = sharedSettings.toFlowSettings()
val flow: Flow<Boolean> = flowSettings.getBooleanFlow("key", false)
fodeguirassy commented 3 years ago

toFlowSettings() seems unavailable. Screenshot 2021-07-21 at 20 47 50

russhwolf commented 3 years ago

Oh sorry. sharedSettings needs to be ObservableSettings to be able to convert to flow.

chris-hatton commented 2 years ago

I'm also stuck trying to use the Flows API's - it looks like they are either missing or out of sync with the documentation. I am on Desktop JVM.

russhwolf commented 2 years ago

Can you say more about what you're trying to do? I believe the documentation is correct and up-to-date but maybe there are missing details that are causing confusion.

Do be aware that Flow APIs are only available for ObservableSettings instances, rather than for all Settings. If you're using the no-arg module you'll need to cast the instance returned by Settings() (but be aware that this won't work on all platforms).