skip to Main Content

I have an enum and I want to modify that enum and delete one of its value.

enum Location {a, b, c}

I want to use the same enum later on in the code but I want to delete the a from Location. How can I do that in Flutter?

After deleted the a the enum Location will be look like this

Location {b, c}

3

Answers


  1. Enum is fixed number of known constant instances. All instances of the enum must be declared in the beginning of the declaration. So we can’t add/delete values from a enum

    Login or Signup to reply.
  2. I don’t know dart, but assuming that enum is an immutable value, just create a function that accepts your enum with a, and constructs a new enum that doesn’t include the a.

    If you’re from Clojure the idea would be something like: (dissoc a Location).

    Forgive me if I’m spouting nonesense. Let me know and I’ll remove the answer.

    Login or Signup to reply.
  3. enums generally cannot be modified as they represent fixed set of values, just define another enum and use it for what you want to achieve e.g

    enum Location { b, c }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search