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.
getBatch({List<String> stringKeys = const <String>[], List<String>? defaultStringValues, List<String> boolKeys = const <String>[], List<bool>? defaultBoolValues, List<String> intKeys = const <String>[], List<int>? defaultIntValues, List<String> largeIntKeys = const <String>[], List<int>? defaultLargeIntValues, List<String> doubleKeys = const <String>[], List<double>? defaultDoubleValues}) → BatchResult
Retrieve multiple key-value pairs of various types in a single operation.
getBool(String key, {bool defaultValue = false}) → bool
Retrieve a bool value for key.
getBoolList(List<String> keys, {List<bool>? defaultValues}) → List<bool>
Retrieve a list of bool values for keys.
getDouble(String key, {double defaultValue = 0.0}) → double
Retrieve a double value for key.
getDoubleList(List<String> keys, {List<double>? defaultValues}) → List<double>
Retrieve a list of double values for keys.
getInt(String key, {int defaultValue = 0}) → int
Retrieve a 32-bit int value for key.
getIntList(List<String> keys, {List<int>? defaultValues}) → List<int>
Retrieve a list of 32-bit int values for keys.
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 String value for key.
getStringList(List<String> keys, {List<String>? defaultValues}) → List<String>
Retrieve a list of String values for keys.
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.
setBatch({List<(String, String)> stringItems = const <(String, String)>[], List<(String, bool)> boolItems = const <(String, bool)>[], List<(String, int)> intItems = const <(String, int)>[], List<(String, int)> largeIntItems = const <(String, int)>[], List<(String, double)> doubleItems = const <(String, double)>[]}) → void
Store multiple key-value pairs of various types in a single operation.
setBool(String key, bool value) → void
Store a bool value for key.
setBoolList(List<(String, bool)> items) → void
Store a list of boolean pairs.
setDouble(String key, double value) → void
Store a double value for key.
setDoubleList(List<(String, double)> items) → void
Store a list of double pairs.
setInt(String key, int value) → void
Store a 32-bit int value for key.
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 String value for key.
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