add fromRawValue constructors to camera_facing, detection_speed and torch_state enums
Showing
3 changed files
with
35 additions
and
0 deletions
| @@ -8,6 +8,17 @@ enum CameraFacing { | @@ -8,6 +8,17 @@ enum CameraFacing { | ||
| 8 | 8 | ||
| 9 | const CameraFacing(this.rawValue); | 9 | const CameraFacing(this.rawValue); |
| 10 | 10 | ||
| 11 | + factory CameraFacing.fromRawValue(int value) { | ||
| 12 | + switch (value) { | ||
| 13 | + case 0: | ||
| 14 | + return CameraFacing.front; | ||
| 15 | + case 1: | ||
| 16 | + return CameraFacing.back; | ||
| 17 | + default: | ||
| 18 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 11 | /// The raw value for the camera facing direction. | 22 | /// The raw value for the camera facing direction. |
| 12 | final int rawValue; | 23 | final int rawValue; |
| 13 | } | 24 | } |
| @@ -18,6 +18,19 @@ enum DetectionSpeed { | @@ -18,6 +18,19 @@ enum DetectionSpeed { | ||
| 18 | 18 | ||
| 19 | const DetectionSpeed(this.rawValue); | 19 | const DetectionSpeed(this.rawValue); |
| 20 | 20 | ||
| 21 | + factory DetectionSpeed.fromRawValue(int value) { | ||
| 22 | + switch (value) { | ||
| 23 | + case 0: | ||
| 24 | + return DetectionSpeed.noDuplicates; | ||
| 25 | + case 1: | ||
| 26 | + return DetectionSpeed.normal; | ||
| 27 | + case 2: | ||
| 28 | + return DetectionSpeed.unrestricted; | ||
| 29 | + default: | ||
| 30 | + return DetectionSpeed.normal; | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + | ||
| 21 | /// The raw value for the detection speed. | 34 | /// The raw value for the detection speed. |
| 22 | final int rawValue; | 35 | final int rawValue; |
| 23 | } | 36 | } |
| @@ -8,6 +8,17 @@ enum TorchState { | @@ -8,6 +8,17 @@ enum TorchState { | ||
| 8 | 8 | ||
| 9 | const TorchState(this.rawValue); | 9 | const TorchState(this.rawValue); |
| 10 | 10 | ||
| 11 | + factory TorchState.fromRawValue(int value) { | ||
| 12 | + switch (value) { | ||
| 13 | + case 0: | ||
| 14 | + return TorchState.off; | ||
| 15 | + case 1: | ||
| 16 | + return TorchState.on; | ||
| 17 | + default: | ||
| 18 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 11 | /// The raw value for the torch state. | 22 | /// The raw value for the torch state. |
| 12 | final int rawValue; | 23 | final int rawValue; |
| 13 | } | 24 | } |
-
Please register or login to post a comment