enum.sbn 713 B

123456789101112131415161718192021222324252627282930
  1. {{~if __this.comment != '' ~}}
  2. //{{escape_comment __this.comment}}
  3. {{~end~}}
  4. enum {{__name}}
  5. {
  6. {{~if !has_enum_item __this~}}
  7. empty_placeholder(0);
  8. {{~else~}}
  9. {{~if !__this.has_zero_value_item ~}}
  10. None(0),
  11. {{~end~}}
  12. {{~end~}}
  13. {{~ for item in __this.items ~}}
  14. {{~if item.comment_or_alias != '' ~}}
  15. //{{escape_comment item.comment_or_alias}}
  16. {{~end~}}
  17. {{item.name}}({{item.int_value}}) {{is_last_enum_item __this item.int_value ? ';' : ','}}
  18. {{~end~}}
  19. final int value;
  20. const {{__name}}(this.value);
  21. static {{__name}} fromValue(int value)
  22. {
  23. return {{__name}}.values.firstWhere((element) => element.value == value, orElse: () => fromValue(0));
  24. }
  25. }