create<T extends Enum> static method
Creates a pod that persists an enum value.
Requires a non-nullable initialValue
to ensure type safety, as there
is no universal default for enums.
Implementation
static Future<TSharedEnumPod<T>> create<T extends Enum>(
String key, {
required Iterable<T> options,
required T initialValue,
}) {
return TSharedEnumPod.create(
key,
fromValue: (rawValue) {
if (rawValue == null) return initialValue;
// Find the enum by its name, or fall back to the initialValue.
return options.firstWhere(
(e) => e.name.toLowerCase() == rawValue.toLowerCase(),
orElse: () => initialValue,
);
},
toValue: (value) => value.name,
initialValue: initialValue,
);
}