Enhanced Enums :
In dart, you can declare enums with members.
For example, for your accounting software you can store company types like Sole Proprietorship, Partnership, Corporation, and Limited Liability Company.
You can declare an enum with members as shown below.
enum Color {
red,
green,
blue,
}
extension ColorExtension on Color {
String get displayName {
switch (this) {
case Color.red:
return 'Red';
case Color.green:
return 'Green';
case Color.blue:
return 'Blue';
default:
throw ArgumentError('Unknown color: $this');
}
}
}
void main() {
print(Color.red.displayName);
}