In the project we have many enums, where each enum item is linked to a String tag.
Currently the "enum value to String" conversion is typically coded with a switch statement.
The code would be more compact and easier to read and maintain if we used static const Map<MyEnum, String> instead.
String get key {
switch (this) {
case TagType.STATES:
return 'states';
case TagType.LABELS:
return 'labels';
case TagType.CATEGORIES:
return 'categories';
case TagType.COUNTRIES:
return 'countries';
case TagType.INGREDIENTS:
return 'ingredients';
case TagType.TRACES:
return 'traces';
case TagType.ADDITIVES:
return 'additives';
case TagType.ALLERGENS:
return 'allergens';
case TagType.LANGUAGES:
return 'languages';
case TagType.EMB_CODES:
return 'emb_codes';
default:
return '';
}
}
Am I missing something important, or should I go on with this refactoring? (about 13 classes impacted, should take 1 hour)
In the project we have many
enum
s, where eachenum
item is linked to aString
tag. Currently the "enum value to String" conversion is typically coded with aswitch
statement. The code would be more compact and easier to read and maintain if we usedstatic const Map<MyEnum, String>
instead.For instance:
instead of
Am I missing something important, or should I go on with this refactoring? (about 13 classes impacted, should take 1 hour)