enum in 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: flutter types class enum

enum CarType {
  sedan,
  suv,
  truck
}

class CarHireCompany {
  CarType storageType;

  CarHireCompany({ this.storageType});
}

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:

Dart Example