dart enum to string code example
Example 1: dart enum
enum Status {
none,
running,
stopped,
paused
}
void main() {
print(Status.values);
Status.values.forEach((v) => print('value: $v, index: ${v.index}'));
print('running: ${Status.running}, ${Status.running.index}');
print('running index: ${Status.values[1]}');
}
Example 2: dart enum from string
Fruit f = Fruit.values.firstWhere((e) => e.toString() == 'Fruit.' + str);