Answers for "dart string enum"

7

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]}'); 
}
Posted by: Guest on August-06-2020
0

dart enum from string

Fruit f = Fruit.values.firstWhere((e) => e.toString() == 'Fruit.' + str);
Posted by: Guest on April-08-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language