Skip to content

Instantly share code, notes, and snippets.

@oussama-dz
Last active June 23, 2023 08:23
Show Gist options
  • Save oussama-dz/6e9ce907fb65ae35cb242e1b5fd443a1 to your computer and use it in GitHub Desktop.
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.
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