Hey Does anyone know of the proper way to call the...
# android
c
Hey Does anyone know of the proper way to call the contains function in Preferences DataStore such that it just returns a Boolean?
Copy code
private fun checkIfKeySet(): Boolean { .. }
Only way I could Think of is using this, but I want the actual Boolean and don't need to observe changes but rather navigate based on output.
Copy code
return dataStore.data.map {
    it.contains(DataStoreConstants.MY_KEY)
}.asLiveData()
Similar shared preferences code was a one liner, so was hoping the same. Also, calling
first()
or
single()
on the flow won't work unless I wrap it in a coroutine which seems unnecessary for a contains check. Any help is appreciated 🙂
i
Every access to the DataStore is asynchronous, so a
suspend
is certainly expected