Pref class abstract

Base interface for defining type-safe preferences.

Implement this interface using enums to create strongly-typed preferences with automatic key generation and default values.

Example:

enum UserPrefs implements Pref {
  theme(PrefType.local, 'dark'),
  language(PrefType.local, 'en'),
  userId(PrefType.remote, ''),
  sessionToken(PrefType.volatile, ''),
  ;

  @override
  final PrefType storageType;
  @override
  final dynamic defaultValue;
  @override
  String get key => name;

  const UserPrefs(this.storageType, this.defaultValue);
}
Available extensions

Constructors

Pref(PrefType storageType, dynamic defaultValue)
const

Properties

defaultValue → dynamic
The default value to use if the preference is not set.
final
hashCode → int
The hash code for this object.
no setterinherited
key → String
The unique key for this preference.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
storageType → PrefType
The storage type for this preference.
final

Methods

clear() → Future<void>

Available on Pref, provided by the PrefExtensions extension

Resets this preference to its default value.
get<T>({T? defaultValueOverride}) → T

Available on Pref, provided by the PrefExtensions extension

Gets the current value of this preference.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set<T>(T value) → Future<void>

Available on Pref, provided by the PrefExtensions extension

Sets a new value for this preference.
toString() → String
A string representation of this object.
inherited

Operators

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