Navaron Bracke

convert mobile scanner state to enhanced enum

1 /// The authorization state of the scanner. 1 /// The authorization state of the scanner.
2 enum MobileScannerState { 2 enum MobileScannerState {
3 /// The scanner has not yet requested the required permissions. 3 /// The scanner has not yet requested the required permissions.
4 - undetermined, 4 + undetermined(0),
5 5
6 /// The scanner has the required permissions. 6 /// The scanner has the required permissions.
7 - authorized, 7 + authorized(1),
8 8
9 /// The user denied the required permissions. 9 /// The user denied the required permissions.
10 - denied 10 + denied(2);
  11 +
  12 + const MobileScannerState(this.rawValue);
  13 +
  14 + factory MobileScannerState.fromRawValue(int value) {
  15 + switch (value) {
  16 + case 0:
  17 + return MobileScannerState.undetermined;
  18 + case 1:
  19 + return MobileScannerState.authorized;
  20 + case 2:
  21 + return MobileScannerState.denied;
  22 + default:
  23 + throw ArgumentError.value(value, 'value', 'Invalid raw value.');
  24 + }
  25 + }
  26 +
  27 + /// The raw value for the state.
  28 + final int rawValue;
11 } 29 }