PrfEnum<T extends Enum> constructor
Creates a new enum preference variable with the specified key
.
values
is required and should be the enum's values list (e.g., MyEnum.values
).
The optional defaultValue
is returned if the preference is not found
or if an error occurs while reading.
Implementation
PrfEnum(super.key, {required List<T> values, super.defaultValue})
: super(
from: (index) {
if (index == null || index < 0 || index >= values.length) {
return null;
}
return values[index];
},
to: (e) => e.index,
getter: (prefs, key) async => await prefs.getInt(key),
setter: (prefs, key, value) async => await prefs.setInt(key, value),
);