SettingsStore class

A store that manages the underlying SharedPreferences with caching.

This class provides a centralized, cached interface to SharedPreferences, eliminating the need for repeated async calls during normal operation. The store initializes asynchronously but provides synchronous access once ready, improving performance for frequent setting access.

The store is used internally by the settings framework and typically doesn't need to be accessed directly by application code.

In test environments, it automatically falls back to regular SharedPreferences to ensure compatibility with test mocking frameworks.

Example internal usage:

final store = SettingsStore();
await store.readyFuture; // Wait for initialization
bool value = store.prefs.getBool('some.key') ?? false;

Constructors

SettingsStore({bool forceRegularSharedPreferences = false})
Creates a new SettingsStore instance. Each instance manages its own SharedPreferences connection.

Properties

hashCode int
The hash code for this object.
no setterinherited
isUsingCache bool
Returns true if using SharedPreferencesWithCache, false if using regular SharedPreferences.
no setter
prefs → dynamic
Provides access to the SharedPreferences instance.
no setter
ready bool
Public getter indicating if the store has been initialized and is ready. When true, the prefs getter can be used synchronously.
no setter
readyFuture Future<bool>
Future that completes when the store is fully initialized. Await this future before accessing settings to ensure proper initialization.
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → void
Disposes of the store and releases resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited