Advertisement
rajath_pai

BluetoothDeviceType

Aug 4th, 2021
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.96 KB | None | 0 0
  1. part of flutter_bluetooth_serial;
  2.  
  3. class BluetoothDeviceType {
  4.   final int underlyingValue;
  5.   final String stringValue;
  6.  
  7.   const BluetoothDeviceType.fromString(String string)
  8.       : this.underlyingValue = (string == 'unknown'
  9.                 ? 0
  10.                 : string == 'classic'
  11.                     ? 1
  12.                     : string == 'le'
  13.                         ? 2
  14.                         : string == 'dual'
  15.                             ? 3
  16.                             : -2 // Unknown, if not found valid
  17.             ),
  18.         this.stringValue = ((string == 'unknown' ||
  19.                     string == 'classic' ||
  20.                     string == 'le' ||
  21.                     string == 'dual' //
  22.                 )
  23.                 ? string
  24.                 : 'unknown' // Unknown, if not found valid
  25.             );
  26.  
  27.   const BluetoothDeviceType.fromUnderlyingValue(int value)
  28.       : this.underlyingValue = ((value >= 0 && value <= 3)
  29.                 ? value
  30.                 : 0 // Unknown, if not found valid
  31.             ),
  32.         this.stringValue = (value == 0
  33.                 ? 'unknown'
  34.                 : value == 1
  35.                     ? 'classic'
  36.                     : value == 2
  37.                         ? 'le'
  38.                         : value == 3
  39.                             ? 'dual'
  40.                             : 'unknown' // Unknown, if not found valid
  41.             );
  42.  
  43.   String toString() => 'BluetoothDeviceType.$stringValue';
  44.  
  45.   int toUnderlyingValue() => underlyingValue;
  46.  
  47.   static const unknown = BluetoothDeviceType.fromUnderlyingValue(0);
  48.   static const classic = BluetoothDeviceType.fromUnderlyingValue(1);
  49.   static const le = BluetoothDeviceType.fromUnderlyingValue(2);
  50.   static const dual = BluetoothDeviceType.fromUnderlyingValue(3);
  51.  
  52.   operator ==(Object other) {
  53.     return other is BluetoothDeviceType &&
  54.         other.underlyingValue == this.underlyingValue;
  55.   }
  56.  
  57.   @override
  58.   int get hashCode => underlyingValue.hashCode;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement