Navaron Bracke

convert phone type to enhanced enum

1 /// Phone number format type constants. 1 /// Phone number format type constants.
2 enum PhoneType { 2 enum PhoneType {
3 /// Unknown phone type. 3 /// Unknown phone type.
4 - ///  
5 - /// Constant Value: 0  
6 - unknown, 4 + unknown(0),
7 5
8 /// Work phone. 6 /// Work phone.
9 - ///  
10 - /// Constant Value: 1  
11 - work, 7 + work(1),
12 8
13 /// Home phone. 9 /// Home phone.
14 - ///  
15 - /// Constant Value: 2  
16 - home, 10 + home(2),
17 11
18 /// Fax machine. 12 /// Fax machine.
19 - ///  
20 - /// Constant Value: 3  
21 - fax, 13 + fax(3),
22 14
23 /// Mobile phone. 15 /// Mobile phone.
24 - ///  
25 - /// Constant Value: 4  
26 - mobile, 16 + mobile(4);
  17 +
  18 + const PhoneType(this.rawValue);
  19 +
  20 + factory PhoneType.fromRawValue(int value) {
  21 + switch (value) {
  22 + case 1:
  23 + return PhoneType.work;
  24 + case 2:
  25 + return PhoneType.home;
  26 + case 3:
  27 + return PhoneType.fax;
  28 + case 4:
  29 + return PhoneType.mobile;
  30 + case 0:
  31 + default:
  32 + return PhoneType.unknown;
  33 + }
  34 + }
  35 +
  36 + /// The raw phone type value.
  37 + final int rawValue;
27 } 38 }