Shared Preferences Storage
class SharedPreferencesStorage(context: Context, prefsName: String = "dev.bloc.hydrated") : HydratedStorage
HydratedStorage backed by SharedPreferences.
State bytes are Base64-encoded before writing so they survive the string-only SharedPreferences API without corruption.
Create once and assign to HydratedBloc.storage at app startup, before any HydratedBlocs are instantiated:
class App : Application() {
override fun onCreate() {
super.onCreate()
HydratedBloc.storage = SharedPreferencesStorage(this)
BlocObserver.shared = AppBlocObserver()
}
}Content copied to clipboard
The SharedPreferences file is named "dev.bloc.hydrated" by default. Override prefsName to use a custom file name (e.g. for migration or testing).