Skip to content

Instantly share code, notes, and snippets.

@mukeshsolanki
Created September 14, 2023 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mukeshsolanki/dedce3951d7c22560e1d370514a9a6e9 to your computer and use it in GitHub Desktop.
Save mukeshsolanki/dedce3951d7c22560e1d370514a9a6e9 to your computer and use it in GitHub Desktop.
// Define a DataStore
val dataStore: DataStore<UserProfile> = context.createDataStore(
fileName = "user_profile.pb",
serializer = UserProfileSerializer // Generated serializer class
)
// Function to retrive the user profile
override suspend fun getUserProfile(): Flow<UserProfle> {
return dataStore.data.map { protoBuilder ->
protoBuilder
}
}
// Function to store the user profile
override suspend fun saveUserProfile(userProfile: UserProfile) {
dataStore.updateData { store ->
store.toBuilder()
.setUserProfile(userProfile)
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment