EnumParsers class
Factory methods for building resilient enum parsing callbacks.
Use these parsers with Convert.toEnum to handle various input formats from
APIs that may return enum values as strings, integers, or mixed casing.
Example
enum Status { pending, active, completed }
// Parse by name
final status = Convert.toEnum(
'active',
parser: EnumParsers.byName(Status.values),
);
// Parse by index
final status2 = Convert.toEnum(
1,
parser: EnumParsers.byIndex(Status.values),
);
See also: EnumValuesParsing for convenient extension methods on enum lists.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
byIndex<
T extends Enum> (List< T> values) → T Function(dynamic) - Creates a parser that matches enum values by their numeric index.
-
byName<
T extends Enum> (List< T> values) → T Function(dynamic) -
Creates a parser that matches enum values by their
Enum.nameproperty. -
byNameCaseInsensitive<
T extends Enum> (List< T> values) → T Function(dynamic) - Creates a parser that matches names case-insensitively.
-
byNameOrFallback<
T extends Enum> (List< T> values, T fallback) → T Function(dynamic) -
Creates a parser that returns
fallbackwhen no matching name is found. -
fromString<
T> (T fromString(String)) → T Function(dynamic) - Wraps a String-based parser to accept dynamic values.