Navaron Bracke

convert address type to enhanced enum

1 /// Address type constants. 1 /// Address type constants.
2 enum AddressType { 2 enum AddressType {
3 /// Unknown address type. 3 /// Unknown address type.
4 - ///  
5 - /// Constant Value: 0  
6 - unknown, 4 + unknown(0),
7 5
8 /// Work address. 6 /// Work address.
9 - ///  
10 - /// Constant Value: 1  
11 - work, 7 + work(1),
12 8
13 /// Home address. 9 /// Home address.
14 - ///  
15 - /// Constant Value: 2  
16 - home, 10 + home(2);
  11 +
  12 + const AddressType(this.rawValue);
  13 +
  14 + factory AddressType.fromRawValue(int value) {
  15 + switch (value) {
  16 + case 1:
  17 + return AddressType.work;
  18 + case 2:
  19 + return AddressType.home;
  20 + case 0:
  21 + default:
  22 + return AddressType.unknown;
  23 + }
  24 + }
  25 +
  26 + /// The raw address type value.
  27 + final int rawValue;
17 } 28 }