A persistent [StorageProvider] implementation backed by AndroidX DataStore Preferences. Part of the Arch Toolkit.
instant().Add as dependency:
implementation("io.github.matheus-corregiari:storage-datastore:<version>")
val provider = DataStoreProvider(store)
val isLoggedIn = provider.boolean("is_logged_in")
val userName = provider.string("user_name")
isLoggedIn.set(true)
println("User: ${userName.instant()}")
enum class Theme { Light, Dark }
val theme = provider.enum("theme", Theme.entries, Theme.Light)
theme.set(Theme.Dark)
println("Theme is ${theme.instant()}")
@kotlinx.serialization.Serializable
data class User(val id: String, val name: String)
val user = provider.model(
key = "user",
fromJson = { Json.decodeFromString<User>(it) },
toJson = { Json.encodeToString(it) }
)
user.set(User("42", "Alice"))
println("User: ${user.instant()}")
| Target | Status |
|---|---|
| Android/JVM | ✅ Persistent (DataStore) |
| iOS/macOS | ✅ Persistent (KMP DataStore) |
| JS/WASM | ⚠️ Stub (noop) |
The Storage DataStore module is part of the Arch Toolkit storage ecosystem:
This module is released under the Apache 2.0 License. See LICENSE for details.