
Simplifies interaction with Jetpack DataStore Preferences through convenient APIs for managing preferences and integrates seamlessly with Jetpack Compose for reactive UI updates. Offers asynchronous operations, preference observation, and supports clearing all preferences.
datastoreutils is a Kotlin Multiplatform utility library designed to simplify interaction with Jetpack DataStore Preferences, offering convenient APIs for common preference operations and seamless integration with Jetpack Compose.
datastoreutils aims to provide a robust and easy-to-use wrapper around Android's Jetpack DataStore Preferences. It abstracts away the complexities of DataStore, offering a clear IPreferencesRepository interface to manage individual preferences (IPreference) across different platforms. Additionally, it provides extensions specifically for Jetpack Compose, enabling reactive observation of preferences directly within your UI.
IPreferencesRepository to create and manage IPreference instances for various data types.IPreference supports:
save).delete).Flow (get).update).currentValue).exists).clearAllPreferences).compose module offers @Composable extension functions to collect preference values as State objects, integrating smoothly with the Compose lifecycle.
collectAsState: Collects Flow values as Compose State.collectAsStateWithLifecycle: Collects Flow values as Compose State respecting a LifecycleOwner and minimum active state.This library is designed for Kotlin Multiplatform projects and supports the following targets:
Add the datastoreutils modules to your build.gradle.kts file.
include("uk.dominikdias.datastoreutils:core:latest")
include("uk.dominikdias.datastoreutils:compose:latest") // If you need Compose integrationsclass MyRepository(dataStore: DataStore<Preferences>): PreferencesRepository(dataStore) {
val foo = createPreference(stringPreferencesKey("foo"), "default_value")
val bar = createPreference(booleanPreferencesKey("bar"), true)
}datastoreutils is a Kotlin Multiplatform utility library designed to simplify interaction with Jetpack DataStore Preferences, offering convenient APIs for common preference operations and seamless integration with Jetpack Compose.
datastoreutils aims to provide a robust and easy-to-use wrapper around Android's Jetpack DataStore Preferences. It abstracts away the complexities of DataStore, offering a clear IPreferencesRepository interface to manage individual preferences (IPreference) across different platforms. Additionally, it provides extensions specifically for Jetpack Compose, enabling reactive observation of preferences directly within your UI.
IPreferencesRepository to create and manage IPreference instances for various data types.IPreference supports:
save).delete).Flow (get).update).currentValue).exists).clearAllPreferences).compose module offers @Composable extension functions to collect preference values as State objects, integrating smoothly with the Compose lifecycle.
collectAsState: Collects Flow values as Compose State.collectAsStateWithLifecycle: Collects Flow values as Compose State respecting a LifecycleOwner and minimum active state.This library is designed for Kotlin Multiplatform projects and supports the following targets:
Add the datastoreutils modules to your build.gradle.kts file.
include("uk.dominikdias.datastoreutils:core:latest")
include("uk.dominikdias.datastoreutils:compose:latest") // If you need Compose integrationsclass MyRepository(dataStore: DataStore<Preferences>): PreferencesRepository(dataStore) {
val foo = createPreference(stringPreferencesKey("foo"), "default_value")
val bar = createPreference(booleanPreferencesKey("bar"), true)
}