Setting<T> class abstract

Abstract base class for all setting types.

This class defines the common interface and functionality for all settings, including type safety, validation, change notifications, and metadata.

Type parameter T ensures compile-time type safety for setting values.

Example usage:

// Create a validated volume setting
final volumeSetting = DoubleSetting(
  key: 'volume',
  defaultValue: 0.5,
  validator: (value) => value >= 0.0 && value <= 1.0,
);

// Listen for changes
volumeSetting.stream.listen((newValue) {
  print('Volume changed to: $newValue');
});

Concrete implementations:

Implemented types
Implementers

Constructors

Setting({required String key, required SettingType type, required T defaultValue, bool userConfigurable = true, dynamic validator, ValidationErrorHandler<T>? onValidationError})
Creates a new setting with the specified configuration.
Setting.fromJson(String json)
Creates a setting from a JSON string representation.
Setting.fromMap(Map<String, dynamic> map)
Creates a setting from a map representation.

Properties

defaultValue → T
The default value used when the setting hasn't been explicitly set.
final
hashCode int
The hash code for this object.
no setterinherited
key String
Unique identifier for this setting within its group.
final
onValidationError ValidationErrorHandler<T>?
Optional handler for validation errors during initialization.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<T>
Stream that emits new values when the setting changes.
no setter
type SettingType
The data type of this setting's value.
final
userConfigurable bool
Whether this setting can be modified by user code.
final
validationDescription String?
Get a human-readable description of the validation rules.
no setter
validator → dynamic
Optional validator for setting values before storage.
final

Methods

attemptRecovery(dynamic invalidValue, String validationError) → T?
Attempts to recover from a validation error using the error handler.
dispose() → void
Dispose of the stream controller and release resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyChange(T value) → void
Internal method to notify all stream listeners of a value change.
toJson() String
Converts the setting to a JSON string representation.
override
toMap() Map<String, dynamic>
Converts the setting to a map.
override
toString() String
A string representation of this object.
inherited
validate(T value) bool
Legacy validation method for backward compatibility.
validateWithResult(T value) ValidationResult<T>
Internal method to validate a value using the validator.

Operators

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