Skip to main content

prefer-enums-by-name

added in: 1.6.0 style

Since Dart 2.15 it's possible to use byName method on enum values prop instead of searching the value with firstWhere.

caution

byName will throw an exception if the enum does not contain a value for the given name.

Example

Bad:

// LINT
final styleDefinition = StyleDefinition.values.firstWhere(
(def) => def.name == json['styleDefinition'],
);

Good:

final styleDefinition = StyleDefinition.values.byName(json['styleDefinition']);