enum dart 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: variables in dart

var nameOfVariable,
//this can be an int, string, or dynamic as well
//example

Example 3: enum flutter

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]}'); 
}

Tags:

Misc Example