enumChoiceValueParser<T> function
ValueParser<T>
enumChoiceValueParser<T>(
- List<
T> values, { - ValuePrinter<
String> ? interceptPrinter,
A specialization of stringChoiceValueParser that uses enumValuePrinter by default in order to parse enums.
If interceptPrinter
is not null
, then it will be called on the result of
enumValuePrinter to modify it.
enum X { a, b, c }
var xParser = enumChoiceValueParser(X.values);
print(xParser('a')); // X.a
xParser('foo'); // throws an exception
Implementation
ValueParser<T> enumChoiceValueParser<T>(List<T> values,
{ValuePrinter<String>? interceptPrinter}) =>
stringChoiceValueParser(values, printer: (value) {
var result = enumValuePrinter(value);
if (interceptPrinter != null) {
result = interceptPrinter(result);
}
return result;
});