Dart How to get the “value” of an enum

后端 未结 15 1840
野的像风
野的像风 2020-12-29 00:50

Before enums were available in Dart I wrote some cumbersome and hard to maintain code to simulate enums and now want to simplify it. I need to get the value of the enum as

15条回答
  •  醉梦人生
    2020-12-29 01:28

    I got so over this I made a package:

    https://pub.dev/packages/enum_to_string

    Also has a handy function that takes enum.ValueOne and parses it to "Value one"

    Its a simple little library but its unit tested and I welcome any additions for edge cases.

提交回复
热议问题