Last active
June 23, 2023 08:23
-
-
Save oussama-dz/6e9ce907fb65ae35cb242e1b5fd443a1 to your computer and use it in GitHub Desktop.
A class for handling the storage of the image URI using datastore.
This file contains hidden or 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
class StoreData { | |
private val Context.storeData: DataStore<Preferences> by preferencesDataStore(name = "data") | |
suspend fun storeImage(context: Context, value: String) { | |
context.storeData.edit { preferences -> | |
preferences[stringPreferencesKey("image")] = value | |
} | |
} | |
suspend fun getImage(context: Context): Flow<String?> { | |
return context.storeData.data.map { | |
preferences -> | |
preferences[stringPreferencesKey("image")] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment