I have an enum and I want to access to it dynamically. I’m not sure if it’s possible or not.
enum EventType {
earthquake,
flood,
fire
}
var event = "fire";
var mytype = EventType.event
You see, what I’m trying to achieve. Is it possible to access the enum like that (using a variable like mytype
)
2
Answers
Try below code
Your Enum:
Just print it:
Output:
fire
Other Way:
You could add this to your enum
then this could work:
Note, using
firstWhereOrNull
requires