Skip to content

Instantly share code, notes, and snippets.

@meet30997
Created September 5, 2022 06:15
Show Gist options
  • Save meet30997/a1a937417a60fff3f93803598d1eb8f2 to your computer and use it in GitHub Desktop.
Save meet30997/a1a937417a60fff3f93803598d1eb8f2 to your computer and use it in GitHub Desktop.
Get Data From DataStore
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