-
-
Save mukeshsolanki/dedce3951d7c22560e1d370514a9a6e9 to your computer and use it in GitHub Desktop.
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
// 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