Skip to main content
The official DataStore setup needs an expect/actual function to find a file path on each platform. FileKit.databasesDir gives you that path from shared code, so the whole setup fits in one file.

Dependencies

build.gradle.kts
datastore-preferences 1.3.0 publishes no Windows native or web targets, and databasesDir doesn’t exist on the web. If your app has those targets, add the dependency and the code below to a source set shared only by the platforms above instead of commonMain.

Create the DataStore

DataStore expects an okio Path, so the last step converts FileKit’s path string with okio’s toPath(). DataStore creates the parent folder when it first writes, so databasesDir doesn’t need to exist yet on desktop. Create only one DataStore per file. A singleton object, or a single instance from your dependency injection, keeps that guarantee. On JVM and Linux native, call FileKit.init(appId) before the first read. See Core setup.

Where the file goes

See App directories for every platform.