-
-
Save mukeshsolanki/81d6eea4298a43da36699bb31852d09c 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 for user preferences | |
val dataStore: DataStore<Preferences> = context.createDataStore(name = "user_preferences") | |
// Define a key for the dark mode | |
val DARK_MODE_KEY = booleanPreferencesKey("dark_mode") | |
// Function to store the toggle value | |
suspend fun storeDarkMode(isOn: Boolean) { | |
dataStore.edit { preferences -> | |
preferences[DARK_MODE_KEY] = isOn | |
} | |
} | |
// Function to retrieve the dark mode value | |
val darkModeFlow: Flow<Boolean?> = dataStore.data.map { preferences -> | |
preferences[DARK_MODE_KEY] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment