SettingsService class Settings
Service for storing persistent key/value application settings.
This object provides a simple typed key-value store persisted to a
platform-specific location. Values are stored inside a named "group" (the
default is DEFAULT) which can be changed with beginGroup/endGroup.
Supported types: String, bool, int (32-bit), large int (64-bit),
and double. Changes are buffered and written to disk either automatically
or immediately when flush is called.
When multiple keys need to be retrieved or stored, the list-based methods (e.g., getStringList, setIntList) can be used for efficiency. Their behavior is similar to the single-value methods, with the addition of handling lists of keys and default values instead of single keys and default values.
Example
final settings = SettingsService();
settings.setString('username', 'alice');
settings.setInt('launchCount', 1);
settings.flush(); // ensure values are persisted
final name = settings.getString('username', defaultValue: 'guest');
Constructors
- SettingsService({String? path})
-
Creates or opens a SettingsService at the given
path.factory - SettingsService.init(int id)
Properties
- group → String
-
The name of the currently active group.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasRegisteredAutoReleaseObject ↔ bool
-
getter/setter pairinherited
- path → String
-
The file system path where this SettingsService stores its values.
no setter
- pointerId → int
-
The pointer ID of the native object
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
beginGroup(
String groupName) → void - Begin a named group for subsequent keys.
-
clear(
) → void - Remove all settings.
-
dispose(
) → void -
Disposes the native object.
inherited
-
endGroup(
) → void -
End the current group and revert to
DEFAULT. -
flush(
) → void - Force-write pending changes to permanent storage.
-
getBool(
String key, {bool defaultValue = false}) → bool -
Retrieve a
boolvalue forkey. -
getBoolList(
List< String> keys, {List<bool> ? defaultValues}) → List<bool> -
Retrieve a list of
boolvalues forkeys. -
getDouble(
String key, {double defaultValue = 0.0}) → double -
Retrieve a
doublevalue forkey. -
getDoubleList(
List< String> keys, {List<double> ? defaultValues}) → List<double> -
Retrieve a list of
doublevalues forkeys. -
getInt(
String key, {int defaultValue = 0}) → int -
Retrieve a 32-bit
intvalue forkey. -
getIntList(
List< String> keys, {List<int> ? defaultValues}) → List<int> -
Retrieve a list of 32-bit
intvalues forkeys. -
getLargeInt(
String key, {int defaultValue = 0}) → int -
Retrieve a 64-bit integer value for
key. -
getLargeIntList(
List< String> keys, {List<int> ? defaultValues}) → List<int> -
Retrieve a list of 64-bit integer values for
keys. -
getString(
String key, {String defaultValue = ''}) → String -
Retrieve a
Stringvalue forkey. -
getStringList(
List< String> keys, {List<String> ? defaultValues}) → List<String> -
Retrieve a list of
Stringvalues forkeys. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerAutoReleaseObject(
int pointerId) → void -
Registers an object for auto release.
inherited
-
remove(
String key) → int - Remove the specified setting key or keys matching a pattern.
-
setBool(
String key, bool value) → void -
Store a
boolvalue forkey. -
setBoolList(
List< (String, bool)> items) → void - Store a list of boolean pairs.
-
setDouble(
String key, double value) → void -
Store a
doublevalue forkey. -
setDoubleList(
List< (String, double)> items) → void - Store a list of double pairs.
-
setInt(
String key, int value) → void -
Store a 32-bit
intvalue forkey. -
setIntList(
List< (String, int)> items) → void - Store a list of integer pairs.
-
setLargeInt(
String key, int value) → void -
Store a 64-bit integer value for
key. -
setLargeIntList(
List< (String, int)> items) → void - Store a list of 64-bit integer pairs.
-
setString(
String key, String value) → void -
Store a
Stringvalue forkey. -
setStringList(
List< (String, String)> items) → void - Store a list of string pairs.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited