Created
September 5, 2022 06:15
-
-
Save meet30997/a1a937417a60fff3f93803598d1eb8f2 to your computer and use it in GitHub Desktop.
Get Data From DataStore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getUserNameWithTryCatch(): Flow<String?> = | |
dataStore.data.catch { exception -> | |
if (exception is IOException) { | |
emit(emptyPreferences()) | |
} else { | |
throw exception | |
} | |
}.map { myDataStore -> | |
myDataStore[userNameKey] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment