Dart – Emulating enums using Constant Constructor

Whilst Dart doesn’t have sup­port for enum types but it turns out you can do a pret­ty good job of emu­lat­ing it using Dart’s con­stant con­struc­tors (which allows you to cre­ate com­pile-time con­stants with your class, which in .Net you’re restrict­ed to num­bers, booleans, strings and null).

Using the tech­nique from this SO answer you will start with a base class for your enum types:

From here, you can cre­ate oth­er spe­cial­ized enum types, such as:


Thank you, mr Ser­gy Akop­kokhyants for this ele­gant lit­tle solu­tion.